演示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");
}
让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:域名注册、虚拟主机、营销软件、网站建设、河池网站维护、网站推广。
分享题目:演示asp.net中使用Repeater嵌套相关代码
网页链接:http://scyanting.com/article/jospci.html