Datagrid columns

R

Rock

Isn't there a way to refer to a column in a datagrid by the name of the
column, rather than the index? This is a dynamically built datagrid, and
when I refer to dg.Column(0), it works fine, but if I refer to
dg.Column("ID"), I get an error saying the string format is incorrect. But
I don't always know what the column number is so I have to refer to it by
name:


With dg
.AutoGenerateColumns = "False"
.CellPadding="4"
.BackColor=Color.White
.BorderWidth = Unit.Pixel(3)
.GridLines=GridLines.Horizontal
.BorderStyle=BorderStyle.Double
.ShowHeader = true
.HeaderStyle.BackColor = Color.Black
.HeaderStyle.ForeColor = Color.White
.HeaderStyle.Font.Bold = true
.EditItemStyle.BackColor = Color.Silver
End With

Dim DGBoundColumnID as New BoundColumn
With DGBoundColumnID
.Visible=False
.DataField="ID"
.ReadOnly=True
End With
dg.Columns.Add(DGBoundColumnID)
 
E

Eliyahu Goldin

Write a simple method that will take the column name as a parameter, loop
through the Column collection and return the column index.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top