I have added a control in the headertemplate of a
datagrid. it's a dropdownlist control. What I want to
be able to do is populate that control based on some
data. My problem is that I can't access the control.
I tried:
DataGrid1.FindControl("frmpriority")
and
(DropDownList)DataGrid1.FindControl("frmpriority")
and
frmpriority (as if it were just a normal control outside
of the datagrid)
but those don't work, it simply cannot find the control.
How can I access the field:
code snippet:
<asp:templatecolumn>
<headertemplate>
Priority<br>
<asp:dropdownlist runat="server"
id="frmpriority"></asp:dropdownlist>
</headertemplate>
<itemtemplate>
Content
</itemtemplate>
</asp:templatecolumn>
thanks
Marshal Antony - 29 Mar 2004 00:53 GMT
Hi David,
Do it in your ItemDataBound event of the datagrid.
if (e.Item.ItemType == ListItemType.Header)
{
DropDownList ddl1=(DropDownList)e.Item.Cells[index].Controls[index];
ddl1.DataSource=your data source (Eg :data reader or dataset) ;
ddl1.DataValueField="coulmn name";
ddl1.DataTextField="column name";
ddl1.DataBind();
}
put the right index for the cell and control.
Hope this helps.
Regards,
Marshal Antony
.NET Developer
http://www.dotnetmarshal.com
> I have added a control in the headertemplate of a
> datagrid. it's a dropdownlist control. What I want to
[quoted text clipped - 26 lines]
>
> thanks