C# 代码隐藏上下文中不存在ID为的WebControl
我在网格视图中看到:C# 代码隐藏上下文中不存在ID为的WebControl,c#,asp.net,C#,Asp.net,我在网格视图中看到: <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyViewTemplate.ascx.cs" Inherits="usercontrols_MyViewTemplate" %> ... <asp:TemplateField HeaderText="Estado" ItemStyle-Width="50px"> <ItemTemplate> &l
<%@ 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>
...
代码隐藏上下文中不存在
RiskWorkDropDownList
。为什么它不存在于代码隐藏中?它嵌套在GridView中,这就是它无法直接访问的原因。你需要像下面这样做
foreach(GridViewRow row in grdView.Rows)
{
if(row.FindControl("RiskWorkDropDownList")!=null)
{
DropDownList ddlRisk = (DropDownList)row.FindControl("RiskWorkDropDownList");
}
}