0

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

SDC
  • 249
  • 2
  • 7
  • 14

1 Answers1

0

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.

Dewfy
  • 23,277
  • 13
  • 73
  • 121
  • This is the first one I have gotten to work. Thanks. The only issue I have now is how I use it in my code. For example in the Page_Load, I get the QueryString location. Depending on the value, I have different blocks of code. I'd like to put this piece within that code instead of a separate OnItemCreated code block. How would I get this done? – SDC May 25 '10 at 16:09
  • Maybe I just don't understand how/when the datalist is built. Maybe I'm just showing my ignorance on how this works. Is it possible to get it outside of OnItemCreated? – SDC May 25 '10 at 19:03
  • @SDC To accomplish this you place this handler 'Item_Created' into the same file where Page_Load is. This event will be executed before Page_load, so variable _pnlArticleHeader will be assigned. In the aspx file for control you need declare event handler: – Dewfy May 26 '10 at 06:01