Find Button Control in DataList Footer

G

Guest

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>
 
G

GrantMagic

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");
}
}
 
H

Hermit Dave

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top