Reputation: 12179
I have this in a grid view:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyViewTemplate.ascx.cs" Inherits="usercontrols_MyViewTemplate" %>
...
<asp:TemplateField HeaderText="Estado" ItemStyle-Width="50px">
<ItemTemplate>
<asp:DropDownList ID="RiskWorkDropDownList" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
And the RiskWorkDropDownList
does not exist in the code behind context. Why doesn't it exist in the code behind?
Upvotes: 0
Views: 82
Reputation: 1275
It is nested within the GridView that's why it is not accessible directly. You needs to do something like below
foreach(GridViewRow row in grdView.Rows)
{
if(row.FindControl("RiskWorkDropDownList")!=null)
{
DropDownList ddlRisk = (DropDownList)row.FindControl("RiskWorkDropDownList");
}
}
Upvotes: 2