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