Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Find Button Control in DataList Footer

Reply
Thread Tools

Find Button Control in DataList Footer

 
 
=?Utf-8?B?Q2hyaXMgRmluaw==?=
Guest
Posts: n/a
 
      09-27-2004
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">
<aspropDownList 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>
</aspropDownList>
</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">
<aspropDownList ID="ddlRuleExclusions_U"
Runat="server"></aspropDownList>
</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>
 
Reply With Quote
 
 
 
 
GrantMagic
Guest
Posts: n/a
 
      09-27-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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">
> <aspropDownList 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>
> </aspropDownList>
> </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">
> <aspropDownList ID="ddlRuleExclusions_U"
> Runat="server"></aspropDownList>
> </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>



 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      09-27-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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">
> <aspropDownList 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>
> </aspropDownList>
> </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">
> <aspropDownList ID="ddlRuleExclusions_U"
> Runat="server"></aspropDownList>
> </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>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any way to reorder how a datagrid is drawn (header/footer/items vs.header/items/footer)? Henrik ASP .Net Datagrid Control 1 07-06-2006 12:23 AM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM
Button in Datalist Footer Error... Chris ASP .Net 3 08-11-2004 04:14 AM
Accessing controls within a datalist footer template Paul Maidment ASP .Net 1 08-07-2003 04:39 PM
Datalist - how (if) to use a sub variable or session variable in the footer? KathyB ASP .Net 1 07-17-2003 01:35 AM



Advertisments