Finding a control in the HEADERTEMPLATE of datagrid.

  • Thread starter Thread starter Dave Mack
  • Start date Start date
D

Dave Mack

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
 
Hi Dave

Might be others, but here's one that worked for me in a quick test: On ItemDataBound for the header row, get the dropdownlist and fill it, like this

Private Sub grdTest_ItemDataBound(ByVal sender As Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
Handles grdTest.ItemDataBoun

If e.Item.ItemType = ListItemType.Header The
Dim ctl As DropDownList =
CType(e.Item.FindControl("ddlHeader"), DropDownList
ctl.Items.Add("Bill"
ctl.Items.Add("Mary"
End I

End Su

hth

Bill

----- Dave Mack wrote: ----

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"
an
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

thank
 
Back
Top