Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

column name in datagrid results

Status
Not open for further replies.

anarayan

Programmer
Joined
May 19, 2005
Messages
3
Location
US
After I bind data to a datagrid, how can I get the column name of a field in the database? I know I can access the values of columns inside each row by accessing e.Item.Dataitem(i) (by looking at e.Item.ItemType) in the ItemCreated event on a databind.

My intention is to change the appearance of data values for only some columns - so is the name of the column stored anywhere so that I can check for it? Otherwise I wouldn't know which column is being bound to a particular dataitem.

arvind
 
Here is another way to do it.

Dim NameoftheDataGrid(,) As String = { _
{"columnheadname", "System.String"}, _
{"columnheadname", "System.String"}, _
{"columnheadname", "System.String"}, _
{"columnheadname", "System.String"}, _
{"columnheadname", "System.Single"}, _
}

.
.
.
'build columns of NameoftheDataGrid table
For y = 0 To UBound(pstnMetric, 1)
dc = New DataColumn
dc.DataType = System.Type.GetType(NameoftheDataGrid(y, 1))
dc.ColumnName = NameoftheDataGrid(y, 0)
dc.ReadOnly = False
dc.Unique = False
xt(0).Columns.Add(dc)
Next

I hope this will give you some ideas of how to do it in another way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top