I am converting a Classic ASP program to C#/asp.net and I don't have a lot of freedom to change displayed code because of customer requirements.
To duplicate the legacy codes appearance, i used a Repeater, like so:
<asp:Repeater ID="ParentRepeater" runat="server">
<HeaderTemplate><%= strHTML %></HeaderTemplate>
<ItemTemplate>
<tr>
<td class="fileRow colHeader">
<div class="chkbx">
<input type="checkbox" id="chkbox" name='<%#Eval("strCheckBox")%>' value='<%#Eval("strCheckBox")%>' />
</div>
<div class="icn" style="background-image: url('<%#val("strGraphic")%>');"> </div>
<div class="flnm"><a href='<%# Eval("strLinkTo") %>'
title='<%# Eval("strLinkTo") %>'><%# Eval("strFileName") %> </a>
<%# Eval("strAdditionalActions") %></div>
<div class="sz"><%# Eval("strSize") %></div>
<div class="typ"><%# Eval("FriendlyType") %></div>
<div class="mddt"><%# Eval("Modified") %> <%# Eval("strTimeZone") %></div>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
I would have liked to have used a a variable for the control ID, but ID's cant be populated at run time. I used a static ID called, "chkbx". This renders as ParentRepeater$ct101$chkbox, with the 101 incrementing for each additional CheckBox in the repeater.
I need to pull the CheckBox name (which is the file name to work with) and if it is checked (meaning its selected for deletion). I have used the following, but have not been able to retrieve control information. The 2 FindControl statement come back as null.
Looping through the Repeater item, I do see something in the results view, but its all repeater info and no control info.
Control cb = FindControl("ParentRepeater$ct101$chkbox") as Control; // ParentRepeater$ct101$chkbox
if (cb != null)
{
}
CheckBox cbx = FindControl("ParentRepeater$ct101$chkbox") as CheckBox; // ParentRepeater$ct101$chkbox
if (cbx != null)
{
}
foreach (RepeaterItem item in ParentRepeater.Items)
{
if(item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
Control btn = item.FindControl("ParentRepeater$ct101$chkbox") as Control;
}
}
Any help would be appreciated.
Eric
Aucun commentaire:
Enregistrer un commentaire