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

這個(gè)演法中,可以看到選擇之后,該行highlight,此功能可以參考這個(gè)鏈接:http://www.dbjr.com.cn/article/33455.htm
下面是Repeater控件Html,有兩個(gè)地方需要注意的,就是CheckBox與Label,這個(gè)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>
<!--下面這個(gè)CheckBox的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td>
<%# Eval("nickname")%>
</td>
<td>
<!--下面這個(gè)Label的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:Label ID="Label1" runat="server" Text=' <%# Eval("mail")%>'></asp:Label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
下面Insus.NET將會(huì)寫一個(gè)方法,也許你的專案不止一個(gè)地方使用到,在需要的地方直接調(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;
}

這個(gè)演法中,可以看到選擇之后,該行highlight,此功能可以參考這個(gè)鏈接:http://www.dbjr.com.cn/article/33455.htm
下面是Repeater控件Html,有兩個(gè)地方需要注意的,就是CheckBox與Label,這個(gè)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>
<!--下面這個(gè)CheckBox的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:CheckBox ID="CheckBox1" runat="server" />
</td>
<td>
<%# Eval("nickname")%>
</td>
<td>
<!--下面這個(gè)Label的ID,注意喔,因?yàn)楹笈_(tái)需要用到它-->
<asp:Label ID="Label1" 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;
}
您可能感興趣的文章:
- asp.net使用Repeater控件中的全選進(jìn)行批量操作實(shí)例
- ASP.NET中repeater控件用法實(shí)例
- 在Repeater控件中通過Eval的方式綁定Style樣式代碼
- Repeater控件與PagedDataSource結(jié)合實(shí)現(xiàn)分頁功能
- Repeater控件實(shí)現(xiàn)編輯、更新、刪除等操作示例代碼
- 給Repeater控件里添加序號(hào)的5種才常見方法介紹
- Repeater控件綁定的三種方式
- Repeater控件動(dòng)態(tài)變更列(Header,Item和Foot)信息實(shí)現(xiàn)思路
- Repeater控件分別綁定數(shù)組和ArrayList實(shí)現(xiàn)思路
- Repeater控件數(shù)據(jù)導(dǎo)出Excel(附演示動(dòng)畫)
- 淺析Repeater控件的使用 (原樣導(dǎo)出和動(dòng)態(tài)顯示/隱藏Repeater中的列)
相關(guān)文章
EF?Core項(xiàng)目中不同數(shù)據(jù)庫需要的安裝包介紹
這篇文章介紹了EF?Core項(xiàng)目中不同數(shù)據(jù)庫需要的安裝包,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05用存儲(chǔ)過程向數(shù)據(jù)庫存值的具體實(shí)現(xiàn)
本文為大家介紹下使用存儲(chǔ)過程向數(shù)據(jù)庫存值的具體實(shí)現(xiàn)過程,感興趣的朋友不要錯(cuò)過2014-01-01深入Lumisoft.NET實(shí)現(xiàn)郵件發(fā)送功能的方法詳解
本篇文章對(duì)使用Lumisoft.NET實(shí)現(xiàn)郵件發(fā)送功能的方法機(jī)型了詳細(xì)的分析介紹。需要的朋友參考下2013-05-05詳解使用DotNet CLI創(chuàng)建自定義的WPF項(xiàng)目模板
這篇文章主要介紹了詳解使用DotNet CLI創(chuàng)建自定義的WPF項(xiàng)目模板,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-04-04一個(gè)完整的ASP.NET 2.0 URL重寫方案[翻譯]
這篇文章描述了一個(gè)完整的 ASP.NET 2.0 URL 重寫方案。這個(gè)方案使用正則表達(dá)式來定義重寫規(guī)則并解決通過虛擬 URLs 訪問頁面產(chǎn)生回發(fā)事件的一些可能的困難。2009-11-11ASP.NET中實(shí)時(shí)圖表的實(shí)現(xiàn)方法分享
這篇文章介紹了ASP.NET中實(shí)時(shí)圖表的實(shí)現(xiàn)方法,有需要的朋友可以參考一下2013-11-11