演示asp.net中使用Repeater嵌套相关代码-创新互联
前台:
<%#Eval("DepId")%>
<%#Eval("Name")%>
后台:
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 Repeater1_ItemDataBound(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(); //取得部门id
//根据当前部门的id从人员表中查找员工的数据
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();
}
}
//提交培训名单
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 != "")
{
//去除最后一个字符
trainPersonsId = trainPersonsId.Substring(0, trainPersonsId.Length - 1);
}
if (trainPersonsNames != "")
{
//去除最后一个字符
trainPersonsNames = trainPersonsNames.Remove(trainPersonsNames.Length - 1);
}
Response.Redirect("add.aspx?trainPersonsId=" + trainPersonsId + "&&trainPersonsNames=" + trainPersonsNames);
//JscriptMsg("提交成功啦!", "add.aspx?trainPersonsId=" + trainPersonsId + "&&trainPersonsNames=" + trainPersonsNames, "Success");
//JscriptMsg("审核通过成功啦!", Utils.CombUrlTxt("list.aspx", "channel_id={0}&keywords={1}&property={2}",
// this.channel_id.ToString(), this.keywords, this.property), "Success");
}
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
本文名称:演示asp.net中使用Repeater嵌套相关代码-创新互联
网页网址:http://cdiso.cn/article/dcsgss.html