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

這個(gè)演法中,可以看到選擇之后,該行highlight,此功能可以參考這個(gè)鏈接:http://m.fzitv.net/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ì)寫(xiě)一個(gè)方法,也許你的專(zhuān)案不止一個(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://m.fzitv.net/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ì)寫(xiě)一個(gè)方法,也許你的專(zhuān)案不止一個(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控件中通過(guò)Eval的方式綁定Style樣式代碼
- Repeater控件與PagedDataSource結(jié)合實(shí)現(xiàn)分頁(yè)功能
- Repeater控件實(shí)現(xiàn)編輯、更新、刪除等操作示例代碼
- 給Repeater控件里添加序號(hào)的5種才常見(jiàn)方法介紹
- 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)畫(huà))
- 淺析Repeater控件的使用 (原樣導(dǎo)出和動(dòng)態(tài)顯示/隱藏Repeater中的列)
相關(guān)文章
.Net?core?Blazor+自定義日志提供器實(shí)現(xiàn)實(shí)時(shí)日志查看器的原理解析
我們經(jīng)常遠(yuǎn)程連接服務(wù)器去查看日志,比較麻煩,如果直接訪問(wèn)項(xiàng)目的某個(gè)頁(yè)面就能實(shí)時(shí)查看日志就比較奈斯了,結(jié)合blazor實(shí)現(xiàn)了基本效果,這篇文章主要介紹了.Net?core?Blazor+自定義日志提供器實(shí)現(xiàn)實(shí)時(shí)日志查看器,需要的朋友可以參考下2022-10-10
ASP.NET檢測(cè)到不安全 Request.Form 值解決方案匯總
這篇文章主要介紹了ASP.NET檢測(cè)到不安全 Request.Form 值解決方案匯總 ,十分的全面,需要的朋友可以參考下2015-06-06
asp.net實(shí)現(xiàn)的計(jì)算網(wǎng)頁(yè)下載速度的代碼
剛看到有人給出asp.net實(shí)現(xiàn)的計(jì)算網(wǎng)頁(yè)下載速度的方法,本方法未經(jīng)本人測(cè)試,不知道能否可靠性如何。準(zhǔn)確來(lái)說(shuō),這只是個(gè)思路吧2013-03-03
.NET Core創(chuàng)建一個(gè)控制臺(tái)(Console)程序
這篇文章主要為大家詳細(xì)介紹了.NET Core如何創(chuàng)建一個(gè)控制臺(tái)程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04

