E_name在当前上下文中不存在

时间:2017-05-30 05:16:11

标签: asp.net

这是我的设计部分。

<asp:Panel ID="eventshow" Visible="false" runat="server" onclick="eventshow_click">
               <asp:Repeater ID="allshowevent" runat="server">
                     <HeaderTemplate>
                     </HeaderTemplate>
                     <ItemTemplate runat="server">
                              <div id="eventab" runat="server">
                                   <div>
                                        <a runat="server" href='Event_Explore.aspx?CID=<%#Eval("CID") %>&FID=<%#Eval("FESTID") %>'>
                                            <asp:Label ID="E_name" runat="server" Text='<%#Eval("EVENT_NAME") %>' onclick="E_nameClick"></asp:Label>
                                        </a>
                                   </div>
                                   <div id="eventdate">
                                       <p>Start Date:<%#Eval("START_DATE") %></p>
                                   </div>
                              </div>
                     </ItemTemplate>
                     <FooterTemplate>
                     </FooterTemplate>
               </asp:Repeater>
</asp:Panel>

这是.cs代码

 protected void E_nameClick(object sender, EventArgs e)
    {

        if (E_name.Text == "GROUP DANCE")
        {
            dan.Visible = true;
        }
    }

它显示当前上下文中不存在e_name。请帮我解决这个问题。 谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用以下内容:

protected void E_nameClick(object sender, EventArgs e)
{
    Label myE_name = (Label)sender;
    ////if dan is inside the repeater then add the following line and replace Control with your control type
    //Control dan = (Control)(((Label)sender).NamingContainer).FindControl("dan");
    if (myE_name.Text == "GROUP DANCE")
    {
        dan.Visible = true;
    }
}