Use Repeater nesting in asp.net to submit the selected checkbox items.

Source: Internet
Author: User

Main Code, passed the test.
Front-end:
<Asp: Repeater ID = "Repeater1" runat = "server" OnItemDataBound = "repeaterincluitemdatabound">

<ItemTemplate>
<Ul>
<Li>
<% # Eval ("DepId") %>
<% # Eval ("Name") %> </li> </ul>
<Asp: Repeater ID = "Repeater2" runat = "server">
<ItemTemplate>
<Asp: CheckBox ID = "cb" runat = "server" Text = '<% # Eval ("RealName") %>'/>
<Asp: HiddenField ID = "hidId" Value = '<% # Eval ("UserId") %> 'runat = "server"/>
</ItemTemplate>
</Asp: Repeater>
</ItemTemplate>
</Asp: Repeater>

 

Background:
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
CF. Model. Department modelDepartment = new CF. Model. Department ();
CF. BLL. Department bllDepartment = new CF. BLL. Department ();
DataSet ds = bllDepartment. GetAllList ();
Repeater1.DataSource = ds. Tables [0]. DefaultView;
Repeater1.DataBind ();
}
}


Protected void repeaterincluitemdatabound (object sender, RepeaterItemEventArgs e)
{
If (e. Item. ItemType = ListItemType. Item | e. Item. ItemType = ListItemType. AlternatingItem)
{
Repeater rp = (Repeater) e. Item. FindControl ("Repeater2 ");
String id = DataBinder. Eval (e. Item. DataItem, "DepId"). ToString (); // obtain the Department id
// Search for employee data from the personnel table based on the id of the current Department
CF. Model. Users modelUsers = new CF. Model. Users ();
CF. BLL. Users bllUsers = new CF. BLL. Users ();
DataSet dsUsers = bllUsers. GetList ("DepId =" + id );
Rp. DataSource = dsUsers. Tables [0]. DefaultView;
Rp. DataBind ();
}
}

// Submit the Training List
Protected void btnSubmit_Click (object sender, EventArgs e)
{
String trainPersonsId = "";
String trainPersonsNames = "";


For (int I = 0; I <this. Repeater1.Items. Count; I ++)
{
Repeater rptPersons = (Repeater) this. Repeater1.Items [I]. FindControl ("Repeater2 ");
For (int j = 0; j <rptPersons. Items. Count; j ++)
{
Int id = Convert. ToInt32 (HiddenField) rptPersons. Items [j]. FindControl ("hidId"). Value );
CheckBox cb = (CheckBox) rptPersons. Items [j]. FindControl ("cb ");
If (cb. Checked)
{
TrainPersonsId + = id + ",";
TrainPersonsNames + = cb. Text. Trim () + ",";
}
}


// Foreach (RepeaterItem item in rptPersons. Items)
//{
// If (item. ItemType = ListItemType. Item | item. ItemType = ListItemType. AlternatingItem)
//{
// CheckBox cb = item. FindControl ("cb") as CheckBox;
// If (cb. Checked)
//{
// TrainPersonsNames + = cb. Text + "| ";
//}
//}
}
If (trainPersonsId! = "")
{
// Remove the last character www.2cto.com
TrainPersonsId = trainPersonsId. Substring (0, trainPersonsId. Length-1 );
}
If (trainPersonsNames! = "")
{
// Remove the last character
TrainPersonsNames = trainPersonsNames. Remove (trainPersonsNames. Length-1 );
}
Response. Redirect ("add. aspx? TrainPersonsId = "+ trainPersonsId +" & trainPersonsNames = "+ trainPersonsNames );


// JscriptMsg ("submitted successfully! "," Add. aspx? TrainPersonsId = "+ trainPersonsId +" & trainPersonsNames = "+ trainPersonsNames," Success ");
// JscriptMsg ("the review is successful! ", Utils. CombUrlTxt (" list. aspx "," channel_id = {0} & keywords = {1} & property = {2 }",
// This. channel_id.ToString (), this. keywords, this. property), "Success ");
}
Author: ekinchen3

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.