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

首頁 > 編程 > .NET > 正文

如何取得Repeater控件選擇的項目及注意事項

2024-07-10 12:54:09
字體:
來源:轉載
供稿:網友

每個項目都會使用到Repeater控件這個功能,而程序員在開發的時候要根據您需要獲取的內容進行更改,今天這篇文章是錯新技術頻道小編為大家帶來的如何取得Repeater控件選擇的項目及注意事項,一起進入下文了解一下吧!

Repeater控件,每個item前有一個CheckBox,把選擇的item列顯出來。

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

復制代碼 代碼如下:

<asp:Repeater ID="RepeaterEmailList" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="1" cellspacing="0" width="96.5%">
<tr>
<td>
?
</td>
<td>
Nickname
</td>
<td>
Email
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="height:10px; line-height:10px;">
<td>
<!--下面這個CheckBox的ID,注意喔,因為后臺需要用到它-->
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td>
<%# Eval("nickname")%>
</td>
<td>
<!--下面這個Label的ID,注意喔,因為后臺需要用到它-->
<asp:Label ID="Label1" runat="server" Text=' <%# Eval("mail")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>


下面Insus.NET將會寫一個方法,也許你的專案不止一個地方使用到,在需要的地方直接調用即可。
GetCheckBoxSelectedValue

?

復制代碼 代碼如下:

?


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;
}

本文是錯新技術頻道小編給大家帶來的如何取得Repeater控件選擇的項目及注意事項,相信大家都學習的差不多了,小編將繼續為大家帶來更多的專業知識。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 民乐县| 临潭县| 磐石市| 罗山县| 康乐县| 鄂伦春自治旗| 恭城| 林州市| 札达县| 晋州市| 固安县| 海淀区| 诸城市| 佛山市| 紫金县| 蚌埠市| 宁夏| 铜山县| 西宁市| 兴业县| 杭州市| 南充市| 旌德县| 永善县| 牡丹江市| 石屏县| 佛山市| 赤壁市| 江达县| 绵竹市| 云南省| 萝北县| 巴林右旗| 营口市| 南宁市| 依安县| 昌邑市| 余江县| 城固县| 息烽县| 江永县|