Home All Groups Group Topic Archive Search About
Author
31 Jan 2005 11:25 PM
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

Author
1 Feb 2005 12:42 PM
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

Show quoteHide quote
"Vishal" <anonym***@discussions.microsoft.com> wrote in message
news:020401c507ec$1f1b8260$a601280a@phx.gbl...
> 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