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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onItemDataBound manipulation deletes header?

Status
Not open for further replies.

link9

Programmer
Nov 28, 2000
3,387
US
Has anyone worked with the onItemDataBound event of a datagrid?

I am working with it now, wanting to change the .text() property of a cell based on the data that's in there. However, every time I touch it, the header for the column no longer appears...

Has anyone experienced this, and solved the problem?

Public Sub dgUsers_OnItemDataBound(ByVal source As Object, ByVal e As DataGridItemEventArgs) Handles dgUsers.ItemDataBound
Dim division As New String(e.Item.Cells(2).Text())
e.Item.Cells(2).Text = getDivision(division)
End Sub

Just trying to do a simple text replacement. And this works just fine, except that the header on the column is lost.

thx-
paul
penny1.gif
penny1.gif
 
Ok -- got this one.

The problem is that onItemDataBound includes the header and footer, as well... and therefore it was trying to replace the text, didn't find an expected value (a number) and therefore returned a blank string, replacing the header.

What the code should look like is this:

if e.item.itemType <> ListItemType.Header Then
e.Item.Cells(3).Text = getDivision(division)
End If

enjoy-
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top