dyanmaically name column in datagrid

  • Thread starter Thread starter MattB
  • Start date Start date
M

MattB

I'm trying to set a column name when my datagrid is being rendered. I've
used the OnItemDataBound event before, so I decided to try and use it again
here.
The problem I'm having is I'm trying to test for a DataColumn from the bound
source with a name of "Info" and I'm not sure how to do that. Here's what
I've been trying:

Sub GuestGrid_OnItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)

'only bother header items

If (e.Item.ItemType = ListItemType.Header) Then

'Set the variable Info column heading text

If Not IsNothing(Trim(e.Item.DataItem("Info"))) Then

e.Item.Cells.Item(0).Text = "testing"

End If

End If

End Sub

------------------------------

The part I'm having trouble with is that If Not
IsNothing(Trim(e.Item.DataItem("Info"))) part. That errors out. How can I
detirmine if there is a column with the name "Info"? Thanks!



Matt
 
You'd Use OnItemDataBound if you're working with the items (rows).
To work with the Columns, you just have to say something like
MyGrid.Columns(0).TeaderText="HeyThere!"
 
That's pretty much what I'm doing, but I was hoping I could base the column
selection on the name of the dataColumn instead of the metric. Looks like I
can't.

Thanks for the reply...

Matt
 
Back
Top