Find Button Control in DataList Footer

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 27, 2004.

  1. This should be relatively simple but I am unable to find an asp:button tag in
    a datalist footer. I have tried it numerous ways including the FindControl
    method from the many events that the DataList exposes and the result is
    always null (I've determined the OnItemDataBound event will not find the
    footer controls). I understand that I have to navigate the datalist object
    tree, but I feel like it is a guessing game and am hesitant to do it that way
    since it will break when new controls are added to the datalist down the
    road. Following is my aspx code:

    <asp:datalist id="dlUnSelected" Runat="server" Width="880"
    CssClass="DataListStyle">
    <HeaderTemplate>
    <tr bgColor="#3342b5">
    <td class="zz" colspan="20" align="left" height="28"><b><font size="2"
    color="#ffffff"><%# ProductID_Desc%> Rules: Available for
    Selection</font></b></td>
    </tr>
    <tr vAlign="top" align=right bgColor="#d3d3d3">
    <td class="dataheader" align="center" width="5" title="Row Number">#</td>
    <td class="dataheader" align="center" width="5"></td>
    <td class="dataheader" align="left" width="250" title="Rule
    Description">RuleDesc</td>
    <td class="dataheader" align="center" width="75" title="LookBack">LB</td>
    <td class="dataheader" align="center" width="75" title="Guardian
    Age">GA</td>
    <td class="dataheader" align="center" width="250" title="Mail Age
    Exclusion">Mail Age Exclusion</td>
    <td class="dataheader" align="center" width="75" title="Mail Age
    Minimum">Age1</td>
    <td class="dataheader" align="center" width="75" title="Mail Age
    Maximum">Age2</td>
    <td class="dataheader" align="center" width="75" title="Rollup
    Description">RollupDesc</td>
    <td class="dataheader" align="center" width="100" title="Rollup
    Minimum">RMN</td>
    <td class="dataheader" align="center" width="100" title="Rollup
    Maximum">RMX</td>
    <td class="dataheader" align="center" width="75" title="Mail Limit">ML</td>
    <td class="dataheader" align="center" width="75" title="Retail
    Limit">RL</td>
    <td class="dataheader" align="center" width="200" title="Rule
    Exclusion">Rule Exclusion</td>
    </tr>
    </HeaderTemplate>
    <ItemTemplate>
    <tr id="trSelected" vAlign="center" align=right bgColor=#f5f5f5
    runat="server">
    <td class="data" align=left width="5"><%=CounterS%>.</td>
    <td class="data" align=left width="5">
    <asp:CheckBox ID="chkBox_U" AutoPostBack="False"
    Runat="server"></asp:CheckBox>
    <input NAME="ruleID_U" type="hidden" id="ruleID_U" value='<%#
    DataBinder.Eval(Container.DataItem, "rule_id")%>' runat="server">
    <input NAME="ruleDesc_U" type="hidden" id="ruleDesc_U" value='<%#
    DataBinder.Eval(Container.DataItem, "description_rule_id")%>'
    runat="server">
    </td>
    <td class="data" align="left" width="250" title="No Rule Description"><%#
    (DataBinder.Eval(Container.DataItem,
    "description_rule_id")).ToString().ToUpper()%></td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtLB_U"
    Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "lookback")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtGA_U"
    Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "guardian_age")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="250">
    <asp:DropDownList ID="ddlMailAgeVerbose_U" AutoPostBack="False"
    Runat="server">
    <asp:ListItem Selected Value="0">Select Range</asp:ListItem>
    <asp:ListItem Value="1">If Under Age1:</asp:ListItem>
    <asp:ListItem Value="2">If Over Age2:</asp:ListItem>
    <asp:ListItem Value="3">If Between Age1 and Age2:</asp:ListItem>
    <asp:ListItem Value="4">If Over Age1 or Under Age2:</asp:ListItem>
    </asp:DropDownList>
    </td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMIN_U"
    Enabled="False" Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "mail_age_min")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMAX_U"
    Enabled="False" Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "mail_age_max")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="75"><%#
    DataBinder.Eval(Container.DataItem, "rollup_description")%></td>
    <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMIN_U"
    Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "rollup_min")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMAX_U"
    Width="30" style="text-align:right" Text='<%#
    DataBinder.Eval(Container.DataItem, "rollup_max")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtML_U"
    Width="30" style="text-align:right" Enabled="False" Text='<%#
    DataBinder.Eval(Container.DataItem, "mail_limit")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="75"><asp:TextBox ID="txtRL_U"
    Width="30" style="text-align:right" Enabled="False" Text='<%#
    DataBinder.Eval(Container.DataItem, "retail_limit")%>'
    Runat="server"></asp:TextBox></td>
    <td class="data" align="center" width="200">
    <asp:DropDownList ID="ddlRuleExclusions_U"
    Runat="server"></asp:DropDownList>
    </td>
    </tr>
    </ItemTemplate>
    <FooterTemplate>
    <tr vAlign="center" align=right bgColor="dcdcdc" height="28">
    <td colspan="20" align="center"><asp:Button ID="btnSubmit_U"
    OnClick="btnSubmit_U_Click" Text="Add Rules" CssClass="graygobtn"
    Runat="server"></asp:Button></td>
    </tr>
    </FooterTemplate>
    </asp:datalist>
     
    =?Utf-8?B?Q2hyaXMgRmluaw==?=, Sep 27, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?Q2hyaXMgRmluaw==?=

    GrantMagic Guest

    For the on item databound method:
    Are you checking for the footer before using the find control method

    I.E.:
    void dlUnSelected_OnItemDataBound(object
    source,DataGridItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Footer)
    {
    Button btn = (Button)e.Item.FindControl("btnSubmit");
    }
    }



    "Chris Fink" <> wrote in message
    news:...
    > This should be relatively simple but I am unable to find an asp:button tag
    > in
    > a datalist footer. I have tried it numerous ways including the
    > FindControl
    > method from the many events that the DataList exposes and the result is
    > always null (I've determined the OnItemDataBound event will not find the
    > footer controls). I understand that I have to navigate the datalist
    > object
    > tree, but I feel like it is a guessing game and am hesitant to do it that
    > way
    > since it will break when new controls are added to the datalist down the
    > road. Following is my aspx code:
    >
    > <asp:datalist id="dlUnSelected" Runat="server" Width="880"
    > CssClass="DataListStyle">
    > <HeaderTemplate>
    > <tr bgColor="#3342b5">
    > <td class="zz" colspan="20" align="left" height="28"><b><font size="2"
    > color="#ffffff"><%# ProductID_Desc%> Rules: Available for
    > Selection</font></b></td>
    > </tr>
    > <tr vAlign="top" align=right bgColor="#d3d3d3">
    > <td class="dataheader" align="center" width="5" title="Row Number">#</td>
    > <td class="dataheader" align="center" width="5"></td>
    > <td class="dataheader" align="left" width="250" title="Rule
    > Description">RuleDesc</td>
    > <td class="dataheader" align="center" width="75" title="LookBack">LB</td>
    > <td class="dataheader" align="center" width="75" title="Guardian
    > Age">GA</td>
    > <td class="dataheader" align="center" width="250" title="Mail Age
    > Exclusion">Mail Age Exclusion</td>
    > <td class="dataheader" align="center" width="75" title="Mail Age
    > Minimum">Age1</td>
    > <td class="dataheader" align="center" width="75" title="Mail Age
    > Maximum">Age2</td>
    > <td class="dataheader" align="center" width="75" title="Rollup
    > Description">RollupDesc</td>
    > <td class="dataheader" align="center" width="100" title="Rollup
    > Minimum">RMN</td>
    > <td class="dataheader" align="center" width="100" title="Rollup
    > Maximum">RMX</td>
    > <td class="dataheader" align="center" width="75" title="Mail
    > Limit">ML</td>
    > <td class="dataheader" align="center" width="75" title="Retail
    > Limit">RL</td>
    > <td class="dataheader" align="center" width="200" title="Rule
    > Exclusion">Rule Exclusion</td>
    > </tr>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <tr id="trSelected" vAlign="center" align=right bgColor=#f5f5f5
    > runat="server">
    > <td class="data" align=left width="5"><%=CounterS%>.</td>
    > <td class="data" align=left width="5">
    > <asp:CheckBox ID="chkBox_U" AutoPostBack="False"
    > Runat="server"></asp:CheckBox>
    > <input NAME="ruleID_U" type="hidden" id="ruleID_U" value='<%#
    > DataBinder.Eval(Container.DataItem, "rule_id")%>' runat="server">
    > <input NAME="ruleDesc_U" type="hidden" id="ruleDesc_U" value='<%#
    > DataBinder.Eval(Container.DataItem, "description_rule_id")%>'
    > runat="server">
    > </td>
    > <td class="data" align="left" width="250" title="No Rule Description"><%#
    > (DataBinder.Eval(Container.DataItem,
    > "description_rule_id")).ToString().ToUpper()%></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtLB_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "lookback")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtGA_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "guardian_age")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="250">
    > <asp:DropDownList ID="ddlMailAgeVerbose_U" AutoPostBack="False"
    > Runat="server">
    > <asp:ListItem Selected Value="0">Select Range</asp:ListItem>
    > <asp:ListItem Value="1">If Under Age1:</asp:ListItem>
    > <asp:ListItem Value="2">If Over Age2:</asp:ListItem>
    > <asp:ListItem Value="3">If Between Age1 and Age2:</asp:ListItem>
    > <asp:ListItem Value="4">If Over Age1 or Under Age2:</asp:ListItem>
    > </asp:DropDownList>
    > </td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMIN_U"
    > Enabled="False" Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_age_min")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMAX_U"
    > Enabled="False" Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_age_max")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><%#
    > DataBinder.Eval(Container.DataItem, "rollup_description")%></td>
    > <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMIN_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "rollup_min")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMAX_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "rollup_max")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtML_U"
    > Width="30" style="text-align:right" Enabled="False" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_limit")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtRL_U"
    > Width="30" style="text-align:right" Enabled="False" Text='<%#
    > DataBinder.Eval(Container.DataItem, "retail_limit")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="200">
    > <asp:DropDownList ID="ddlRuleExclusions_U"
    > Runat="server"></asp:DropDownList>
    > </td>
    > </tr>
    > </ItemTemplate>
    > <FooterTemplate>
    > <tr vAlign="center" align=right bgColor="dcdcdc" height="28">
    > <td colspan="20" align="center"><asp:Button ID="btnSubmit_U"
    > OnClick="btnSubmit_U_Click" Text="Add Rules" CssClass="graygobtn"
    > Runat="server"></asp:Button></td>
    > </tr>
    > </FooterTemplate>
    > </asp:datalist>
     
    GrantMagic, Sep 27, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?Q2hyaXMgRmluaw==?=

    Hermit Dave Guest

    i think you should be alright using the ItemCreated event. The footer is not
    accessible in ItemDataBound event handler.
    for itemcreated try something like this

    if(e.ItemType == ListItemType.Footer)
    {
    // a find control should be alright here
    Button btnSubmit = e.FindControl("btnSubmit_U");

    // whatever you need to do with the button here.
    }

    other way would be to iterate the Items collection of DataList

    forearch(DataListItem dli in this.dlUnSelected.Items)
    {
    if(dli.ItemType == ListItemType.Footer)
    {
    // do a find control and whatever else needs to be done

    }
    }

    --

    Regards,

    Hermit Dave
    (http://hdave.blogspot.com)
    "Chris Fink" <> wrote in message
    news:...
    > This should be relatively simple but I am unable to find an asp:button tag
    > in
    > a datalist footer. I have tried it numerous ways including the
    > FindControl
    > method from the many events that the DataList exposes and the result is
    > always null (I've determined the OnItemDataBound event will not find the
    > footer controls). I understand that I have to navigate the datalist
    > object
    > tree, but I feel like it is a guessing game and am hesitant to do it that
    > way
    > since it will break when new controls are added to the datalist down the
    > road. Following is my aspx code:
    >
    > <asp:datalist id="dlUnSelected" Runat="server" Width="880"
    > CssClass="DataListStyle">
    > <HeaderTemplate>
    > <tr bgColor="#3342b5">
    > <td class="zz" colspan="20" align="left" height="28"><b><font size="2"
    > color="#ffffff"><%# ProductID_Desc%> Rules: Available for
    > Selection</font></b></td>
    > </tr>
    > <tr vAlign="top" align=right bgColor="#d3d3d3">
    > <td class="dataheader" align="center" width="5" title="Row Number">#</td>
    > <td class="dataheader" align="center" width="5"></td>
    > <td class="dataheader" align="left" width="250" title="Rule
    > Description">RuleDesc</td>
    > <td class="dataheader" align="center" width="75" title="LookBack">LB</td>
    > <td class="dataheader" align="center" width="75" title="Guardian
    > Age">GA</td>
    > <td class="dataheader" align="center" width="250" title="Mail Age
    > Exclusion">Mail Age Exclusion</td>
    > <td class="dataheader" align="center" width="75" title="Mail Age
    > Minimum">Age1</td>
    > <td class="dataheader" align="center" width="75" title="Mail Age
    > Maximum">Age2</td>
    > <td class="dataheader" align="center" width="75" title="Rollup
    > Description">RollupDesc</td>
    > <td class="dataheader" align="center" width="100" title="Rollup
    > Minimum">RMN</td>
    > <td class="dataheader" align="center" width="100" title="Rollup
    > Maximum">RMX</td>
    > <td class="dataheader" align="center" width="75" title="Mail
    > Limit">ML</td>
    > <td class="dataheader" align="center" width="75" title="Retail
    > Limit">RL</td>
    > <td class="dataheader" align="center" width="200" title="Rule
    > Exclusion">Rule Exclusion</td>
    > </tr>
    > </HeaderTemplate>
    > <ItemTemplate>
    > <tr id="trSelected" vAlign="center" align=right bgColor=#f5f5f5
    > runat="server">
    > <td class="data" align=left width="5"><%=CounterS%>.</td>
    > <td class="data" align=left width="5">
    > <asp:CheckBox ID="chkBox_U" AutoPostBack="False"
    > Runat="server"></asp:CheckBox>
    > <input NAME="ruleID_U" type="hidden" id="ruleID_U" value='<%#
    > DataBinder.Eval(Container.DataItem, "rule_id")%>' runat="server">
    > <input NAME="ruleDesc_U" type="hidden" id="ruleDesc_U" value='<%#
    > DataBinder.Eval(Container.DataItem, "description_rule_id")%>'
    > runat="server">
    > </td>
    > <td class="data" align="left" width="250" title="No Rule Description"><%#
    > (DataBinder.Eval(Container.DataItem,
    > "description_rule_id")).ToString().ToUpper()%></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtLB_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "lookback")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtGA_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "guardian_age")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="250">
    > <asp:DropDownList ID="ddlMailAgeVerbose_U" AutoPostBack="False"
    > Runat="server">
    > <asp:ListItem Selected Value="0">Select Range</asp:ListItem>
    > <asp:ListItem Value="1">If Under Age1:</asp:ListItem>
    > <asp:ListItem Value="2">If Over Age2:</asp:ListItem>
    > <asp:ListItem Value="3">If Between Age1 and Age2:</asp:ListItem>
    > <asp:ListItem Value="4">If Over Age1 or Under Age2:</asp:ListItem>
    > </asp:DropDownList>
    > </td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMIN_U"
    > Enabled="False" Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_age_min")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtMAMAX_U"
    > Enabled="False" Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_age_max")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><%#
    > DataBinder.Eval(Container.DataItem, "rollup_description")%></td>
    > <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMIN_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "rollup_min")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="100"><asp:TextBox ID="txtRUMAX_U"
    > Width="30" style="text-align:right" Text='<%#
    > DataBinder.Eval(Container.DataItem, "rollup_max")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtML_U"
    > Width="30" style="text-align:right" Enabled="False" Text='<%#
    > DataBinder.Eval(Container.DataItem, "mail_limit")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="75"><asp:TextBox ID="txtRL_U"
    > Width="30" style="text-align:right" Enabled="False" Text='<%#
    > DataBinder.Eval(Container.DataItem, "retail_limit")%>'
    > Runat="server"></asp:TextBox></td>
    > <td class="data" align="center" width="200">
    > <asp:DropDownList ID="ddlRuleExclusions_U"
    > Runat="server"></asp:DropDownList>
    > </td>
    > </tr>
    > </ItemTemplate>
    > <FooterTemplate>
    > <tr vAlign="center" align=right bgColor="dcdcdc" height="28">
    > <td colspan="20" align="center"><asp:Button ID="btnSubmit_U"
    > OnClick="btnSubmit_U_Click" Text="Add Rules" CssClass="graygobtn"
    > Runat="server"></asp:Button></td>
    > </tr>
    > </FooterTemplate>
    > </asp:datalist>
     
    Hermit Dave, Sep 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    1
    Views:
    442
  2. Paul Maidment
    Replies:
    1
    Views:
    4,457
    Nick Berardi
    Aug 7, 2003
  3. Chris

    Button in Datalist Footer Error...

    Chris, Aug 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,686
    Rick Spiewak
    Aug 11, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,966
  5. Henrik
    Replies:
    1
    Views:
    463
    Ken Cox [Microsoft MVP]
    Jul 6, 2006
Loading...

Share This Page