国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 芦溪县| 晋中市| 呼和浩特市| 巴林左旗| 邳州市| 汾西县| 饶阳县| 新化县| 廉江市| 呼和浩特市| 青川县| 大同市| 抚顺市| 伊春市| 迁安市| 富宁县| 宁乡县| 鹿邑县| 科技| 拜城县| 通化市| 阿荣旗| 神木县| 壤塘县| 榆社县| 晋中市| 博野县| 苏尼特右旗| 沾益县| 昭通市| 邻水| 南宫市| 谢通门县| 柏乡县| 习水县| 玉山县| 龙川县| 灵川县| 新龙县| 黔西县| 灵川县|