Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 代码隐藏上下文中不存在ID为的WebControl_C#_Asp.net - Fatal编程技术网

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");
        }
}