如何取得Repeater控件選擇的項目及注意事項
更新時間:2013年01月25日 10:15:16 作者:
Repeater控件,每個item前有一個CheckBox,把選擇的item列顯出來,有兩個地方需要注意的,就是CheckBox與Label,這個Label是隨你需要獲取的內(nèi)容而變化喔。如你想獲取Nickname,那你需要把綁定的的內(nèi)容放在Label上
Repeater控件,每個item前有一個CheckBox,把選擇的item列顯出來。

這個演法中,可以看到選擇之后,該行highlight,此功能可以參考這個鏈接:http://chabaoo.cn/article/33455.htm
下面是Repeater控件Html,有兩個地方需要注意的,就是CheckBox與Label,這個Label是隨你需要獲取的內(nèi)容而變化喔。如你想獲取Nickname,那你需要把綁定的的內(nèi)容放在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將會寫一個方法,也許你的專案不止一個地方使用到,在需要的地方直接調(diào)用即可。
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;
}

這個演法中,可以看到選擇之后,該行highlight,此功能可以參考這個鏈接:http://chabaoo.cn/article/33455.htm
下面是Repeater控件Html,有兩個地方需要注意的,就是CheckBox與Label,這個Label是隨你需要獲取的內(nèi)容而變化喔。如你想獲取Nickname,那你需要把綁定的的內(nèi)容放在Label上。
Repeater & CheckBox
復(fù)制代碼 代碼如下:
<asp:Repeater ID="RepeaterEmailList" runat="server">
<HeaderTemplate>
<table border="1" cellpadding="1" cellspacing="0" width="96.5%">
<tr>
<td>
</td>
<td>
Nickname
</td>
<td>
</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將會寫一個方法,也許你的專案不止一個地方使用到,在需要的地方直接調(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;
}
您可能感興趣的文章:
- asp.net使用Repeater控件中的全選進行批量操作實例
- ASP.NET中repeater控件用法實例
- 在Repeater控件中通過Eval的方式綁定Style樣式代碼
- Repeater控件與PagedDataSource結(jié)合實現(xiàn)分頁功能
- Repeater控件實現(xiàn)編輯、更新、刪除等操作示例代碼
- 給Repeater控件里添加序號的5種才常見方法介紹
- Repeater控件綁定的三種方式
- Repeater控件動態(tài)變更列(Header,Item和Foot)信息實現(xiàn)思路
- Repeater控件分別綁定數(shù)組和ArrayList實現(xiàn)思路
- Repeater控件數(shù)據(jù)導(dǎo)出Excel(附演示動畫)
- 淺析Repeater控件的使用 (原樣導(dǎo)出和動態(tài)顯示/隱藏Repeater中的列)
相關(guān)文章
EF?Core項目中不同數(shù)據(jù)庫需要的安裝包介紹
這篇文章介紹了EF?Core項目中不同數(shù)據(jù)庫需要的安裝包,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05用存儲過程向數(shù)據(jù)庫存值的具體實現(xiàn)
本文為大家介紹下使用存儲過程向數(shù)據(jù)庫存值的具體實現(xiàn)過程,感興趣的朋友不要錯過2014-01-01深入Lumisoft.NET實現(xiàn)郵件發(fā)送功能的方法詳解
本篇文章對使用Lumisoft.NET實現(xiàn)郵件發(fā)送功能的方法機型了詳細的分析介紹。需要的朋友參考下2013-05-05詳解使用DotNet CLI創(chuàng)建自定義的WPF項目模板
這篇文章主要介紹了詳解使用DotNet CLI創(chuàng)建自定義的WPF項目模板,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04