国产探花免费观看_亚洲丰满少妇自慰呻吟_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控件選擇的項目及注意事項,相信大家都學習的差不多了,小編將繼續為大家帶來更多的專業知識。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 云和县| 夏河县| 鹤岗市| 胶州市| 宁乡县| 西宁市| 抚顺县| 双鸭山市| 新巴尔虎左旗| 日土县| 章丘市| 洪雅县| 新营市| 宁都县| 察哈| 阳新县| 资溪县| 轮台县| 呼图壁县| 芦溪县| 多伦县| 香港| 图木舒克市| 溧阳市| 勐海县| 桦川县| 界首市| 额敏县| 阳谷县| 揭阳市| 柯坪县| 浦县| 万宁市| 兰州市| 安塞县| 邵东县| 灵石县| 武宣县| 峨山| 新巴尔虎右旗| 深水埗区|