By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,353 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,353 IT Pros & Developers. It's quick & easy.

dyanmaically name column in datagrid

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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!"

"MattB" <so********@yahoo.com> wrote in message
news:2g***********@uni-berlin.de...
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

Nov 18 '05 #2

P: n/a
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

David Jessee wrote:
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!"

"MattB" <so********@yahoo.com> wrote in message
news:2g***********@uni-berlin.de...
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


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.