Hi

The Items Collection of DataGrid does not hold Header and Footer. So to
access the Control you need to handle ItemCreated event.

HTH
Prasad

"Robert Hui" <anonymous@devdex.com> wrote in message
news:eHWq7v3RDHA.3880@tk2msftngp13.phx.gbl...
>
> Hi
>
> I have created a textbox control in the Datagrid column header. Like
> this:
>
> In form.aspx file:
> <asp:DataGrid id="grdHeader">
> <Column>
> <asp:TemplateColumn>
> <ItemTemplate>
> <%# DataBinder.Eval(Container.DataItem,"FieldName")%>
> </ItemTemplate>
> <HeaderTemplate>
> <asp:TextBox id="txtTest" Runat="server">
> </asp:TextBox>
> </HeaderTemplate>
>
> </asp:TemplateColumn>
> </Column>
> </asp:DataGrid>
>
> In form.aspx.cs file:
>
> Put on htmlServerControl such as "cmdClick"
>
> On cmbClick's ServerClick event, I have wrote code like:
>
> grdHeader.Items[0].FindControl("txtTest")
>
> or
>
> foreach (DataGridItem di in grdHeader.Items)
> {
> TextBox txtValue=(TextBox)di.FinControl("txtTest");
> string strValue=txtValue.Text;
> }
>
> Both of them are failed, the FindControl statement reture null
> reference.
>
> I also have tried decalre same name of control in form.aspx.cs file
> class definition. Then call like that:
>
> strValue=txtTest.Text;
>
> But the result still same.
>
> Could anyone know how to implment this? I know the DataGridItem not
> includes header, so the above statement will fail, but which I can use
> to get the value that entered from client side.
>
> Thanks in advance.
>
> Regards
>
> Robert
>
>
>
>
>
>
>
> *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
> Don't just participate in USENET...get rewarded for it!