Get Header Text

V

Vishal

Hello,

I am trying to get the header text of the datagrid in
the ItemDataBound event, but it returns an empty string.

Here is what I did:
Private Sub datagrid1_ItemDataBound(....)
If e.Item.ItemType = ListItemType.Header Then
Response.Write("Header Text" & e.Item.Cells(2).Text)
End If
end Sub

And here is my desinger of the datagrid.

<asp:datagrid id=....>
....
<asp:TemplateColumn>
...
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="Day" HeaderText="Date">
...
</asp:TemplateColumn>
....
</asp:datagrid>

What I am doing wroing? I also tried the same code in the
OnItemCreated event, but it returns also an empty string.

Thanks
 
K

Ken Cox [Microsoft MVP]

Hi Vishal,

Try using the PreRender event?

Private Sub DataGrid1_PreRender _
(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DataGrid1.PreRender
Dim dgCell As TableCell
dgCell = CType(DataGrid1.Controls(0). _
Controls(0). _
Controls(0), _
TableCell)
Response.Write(dgCell.Text)
End Sub

Ken
Microsoft MVP [ASP.NET]
Toronto
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top