Hi,
Don't use Datagrid variable declared in the code behind file.
for example: Datagrid1.FindControl
Asp.net page may not assign the datagrid object which post back from client,
after it's initialized in the Initialize component method.
But the datagrid object from the client is really existed in the form
object, because client postback everything in the form tag. So you can still
have it.
And please remember there is control hierarchy, and your object which
generate event is also in the hierarchy which is hierarchy of page object.
Then, you consider to use like the following in the event handler:
private void DataList_ItemCommand(Object sender, DataGridCommandEventArgs e)
{
DataGrid dtg = (DataGrid)sender.Parent.Parent.Parent;
Label lbl = (Label)dtg.FindControl("lblID");
}
In the event handler,
->sender is the source object which raise event.
->sender.Parent might be a cell of the datagrid that hold the control which
raise event.
->sender.Parent.Parent might be a row of the datagrid that hold the cell.
->sender.Parent.Parent.Parent might be datagrid that hold the row.
Now, you get the existing datagrid in the page and you can find your control.
Enjoy it!
--
Regards,
Kyaw Zayar Han
[quoted text, click to view] "Ajoy" wrote:
> Hi,
>
> I have a label control which resides in the header template of a template
> column in a datagrid. I have to reference this label control from the event
> handler of a Datalist control.
> DataList_ItemCommand is the function in which I have to reference the label
> control of datagrid.
> How do I find it. Datagrid.FindControl does not find this control because it
> is in header template of datagrid.
>
> Please advise
>
> Thank you
> Ajoy
>
>