Question

i am updating my table by placing datailsview in the webpage and giving it a datasource,

i have introduced a dropdownlist in the middle of bounded control and want it to be filled according to my given instruction, but the DropDownList is not accessible via ID in code-behind, e.g.:

<asp:TemplateField>
    <ItemTemplate>
        <asp:DropDownList ID="drpdownlist" DataSourceID="deptsource" Width="150px" DataTextField="deptname" DataValueField="deptid" runat="server" />
    </ItemTemplate>
</asp:TemplateField>
Was it helpful?

Solution

First you need to use the FindControl() method after rows are databound as abatishchev mentioned. Also, you need to remember that this wont be possible until there are in fact some rows in the grid. But you need to also remember that you will not get just one DropDownList, but instead there will be one DropDownList for each row in your GridView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top