I am attempting to use a findcontrol method to dynamically fill a drop down list. I keep getting a null reference and have tried a couple different ways. Here is some code that Ive tried.
<ItemTemplate>
<asp:DropDownList runat="server"
ID="ddlCalculateGrid"
Style="border: none; border-width: 0px; width: 90%"
OnSelectedIndexChanged="ddlCalculateGrid_OnSelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
<asp:HiddenField runat="server"
ID="hdnCalculate"
Value='<%# Eval("Calculate") %>' />
</ItemTemplate>
and here is the back end code.
DropDownList tempddl;
tempddl = (DropDownList)grvbillDetail.FindControl("ddlCalculateGrid");
tempddl.DataSource = rcta.GetDataByTrueValue();
tempddl.DataBind();
Your dropdown is in an item template. This means your gridview could contain several drop downs (one in each row) or none at all if the gridview is bound to a source with no rows.
If you’re looking to bind each dropdown for each row, you would do so in the GridViewRowDatabound event like so.