How to obtain the items selected by the Repeater control and precautions

Source: Internet
Author: User

The Repeater control. Each item has a CheckBox before it displays the selected item column.

In this method, you can see the line of highlight after the selection, this function can refer to this link: http://www.jb51.net/article/33455.htm
The following is the Repeater control Html. There are two things to note: CheckBox and Label. This Label varies with the content you need. If you want to obtain the nick name, you need to put the bound content on the Label.
Repeater & CheckBox
Copy codeThe Code is as follows:
<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>
<! -- The ID of the CheckBox below. Note that it is used in the background -->
<Asp: CheckBox ID = "CheckBox1" runat = "server"/>
</Td>
<Td>
<% # Eval ("nickname") %>
</Td>
<Td>
<! -- Note the ID of the Label below, because it is needed in the background -->
<Asp: Label ID = "Label1" runat = "server" Text = '<% # Eval ("mail") %>'> </asp: Label>
</Td>
</Tr>
</ItemTemplate>
<FooterTemplate>
</Table>
</FooterTemplate>
</Asp: Repeater>

The following Insus. NET will write a method. Maybe your project is used in more than one place and can be called directly as needed.
GetCheckBoxSelectedValue
Copy codeThe Code is as follows:
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;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.