国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

如何取得Repeater控件選擇的項(xiàng)目及注意事項(xiàng)

2024-07-10 13:17:55
字體:
供稿:網(wǎng)友
Repeater控件,每個(gè)item前有一個(gè)CheckBox,把選擇的item列顯出來。

如何取得Repeater控件選擇的項(xiàng)目及注意事項(xiàng)


這個(gè)演法中,可以看到選擇之后,該行highlight,此功能可以參考這個(gè)鏈接:
下面是Repeater控件Html,有兩個(gè)地方需要注意的,就是CheckBox與Label,這個(gè)Label是隨你需要獲取的內(nèi)容而變化喔。如你想獲取Nickname,那你需要把綁定的的內(nèi)容放在Label上。
Repeater & CheckBox

復(fù)制代碼 代碼如下:


<asp:Repeater runat="server">
<HeaderTemplate>
<table cellpadding="1" cellspacing="0">
<tr>
<td>
 
</td>
<td>
Nickname
</td>
<td>
Email
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<!--下面這個(gè)CheckBox的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:CheckBox runat="server" />
</td>
<td>
<%# Eval("nickname")%>
</td>
<td>
<!--下面這個(gè)Label的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:Label runat="server" Text=' <%# Eval("mail")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>


下面Insus.NET將會(huì)寫一個(gè)方法,也許你的專案不止一個(gè)地方使用到,在需要的地方直接調(diào)用即可。
GetCheckBoxSelectedValue

復(fù)制代碼 代碼如下:


private string GetCheckBoxSelectedValue(Repeater repeater, string checkBoxId,string labelId)
{
string tempValue = string.Empty;
foreach (RepeaterItem item in repeater.Items)
{
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
if (item.FindControl(checkBoxId) != null && item.FindControl(labelId) != null)
{
CheckBox cb = (CheckBox)item.FindControl(checkBoxId);
Label lbl = (Label)item.FindControl(labelId);
if (cb.Checked)
{
tempValue = tempValue + ";" + lbl.Text;
}
}
}
}
if (tempValue.Length > 0)
{
tempValue = tempValue.Substring(2);
}
return tempValue;
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 六安市| 宁远县| 江山市| 宿州市| 广丰县| 丽水市| 榆树市| 南城县| 黄梅县| 彭山县| 临武县| 安庆市| 肥城市| 辉南县| 炎陵县| 龙江县| 大关县| 龙海市| 木里| 通辽市| 富平县| 海门市| 伊吾县| 抚顺县| 永修县| 青川县| 东莞市| 纳雍县| 那坡县| 寻乌县| 昌平区| 和田市| 方正县| 阜康市| 五峰| 广丰县| 桦南县| 大城县| 辽源市| 呼伦贝尔市| 娄烦县|