开发者

ASP.NET Panel FindControl within DataList to change property C#

开发者 https://www.devze.com 2022-12-31 08:05 出处:网络
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 try

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=开发者_StackOverflow社区"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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消