DataList 中的 ASP.NET 面板 FindControl 更改属性 C#

发布于 2024-09-03 02:09:56 字数 866 浏览 3 评论 0原文

我对 ASP.NET 很陌生。在我的页面中,我有一个带有页脚模板的数据列表。在页脚中,我有几个面板,它们将根据查询字符串可见。我遇到的问题是尝试在 Page_Load 上找到这些面板以更改可见属性。有没有办法在Page_Load中找到这个控件?例如,这是 aspx 页面的一部分:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <asp:DataList ID="dlRecords" runat="server">
  <FooterTemplate>
   <asp:Panel ID="pnlArticleHeader" runat="server" Visible="false" >
   </asp:Panel>
  </FooterTemplate>
 </asp:Datalist>
</asp:Content>

这是代码隐藏中的内容:

protected void Page_Load(object sender, EventArgs e)
    {
        location = Request.QueryString["location"];
        if (location == "HERE")
        {
          Panel pnlAH = *Need to find control here*;
          pnlAH.Visible=true;
         }
      }

就像我说的,我对此很陌生。我发现的所有内容似乎都不起作用,因此我决定发布一个具体问题。提前致谢

I'm new to this ASP.NET stuff. In my page I have a Datalist with a FooterTemplate. In the footer I have a couple panels that will be visible depending on the QueryString. The problem I am having is trying to find these panels on Page_Load to change the Visible Property. Is there a way to find this control in the Page_Load? For example this is part of the aspx page:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <asp:DataList ID="dlRecords" runat="server">
  <FooterTemplate>
   <asp:Panel ID="pnlArticleHeader" runat="server" Visible="false" >
   </asp:Panel>
  </FooterTemplate>
 </asp:Datalist>
</asp:Content>

Here is something in the codebehind:

protected void Page_Load(object sender, EventArgs e)
    {
        location = Request.QueryString["location"];
        if (location == "HERE")
        {
          Panel pnlAH = *Need to find control here*;
          pnlAH.Visible=true;
         }
      }

Like I said I am new at this. Everything I have found doesn't seem to work so I decided to post a specific question. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖 2024-09-10 02:09:56

DataList 有事件 OnItemCreated,重写允许选择行类型:

  Panel _pnlArticleHeader;
  void Item_Created(Object sender, DataListItemEventArgs e)
  {

     if (e.Item.ItemType == ListItemType.Footer)
     {

        _pnlArticleHeader =(Panel)e.Item.FindControl("pnlArticleHeader");
      }

  }

在字段中调用事件后:_pnlArticleHeader 您将获得所需的面板。这种方式很安全,因为只创建一次。笔记!对于普通 DataList 的行,同样的方式将仅返回最后一行。

DataList has event OnItemCreated, overriding allows select type of row:

  Panel _pnlArticleHeader;
  void Item_Created(Object sender, DataListItemEventArgs e)
  {

     if (e.Item.ItemType == ListItemType.Footer)
     {

        _pnlArticleHeader =(Panel)e.Item.FindControl("pnlArticleHeader");
      }

  }

After event invocation in the field: _pnlArticleHeader you will get desired panel. This way is safe since created only once. NOTE! same way for common DataList's row would return only last one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文