两个或多个 Repeater 嵌套在一起显示分级数据:
首先,在最外层的那个 Repeater1 的 Repeater1_ItemDataBound 事件中:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//DataRowView rowv = (DataRowView)e.Item.DataItem;
//string strClassID = Convert.ToString(rowv["ClassID"]);
Label LabelID = (Label)e.Item.FindControl("Label1");
string parentID = LabelID.Text.ToString();//此岗位的ID号
string sql = "select A.*,B.PositionName from CandidateUser AS A,PositionTable AS B where A.WantPosition = B.ID and A.WantPosition = '" + parentID + "' order by A.UID asc"; //取出应聘此岗位的所有人员
DataSet ds = newdb.CommonDataSet(sql);
Repeater subRepeater = (Repeater)e.Item.FindControl("Repeater2");
subRepeater.DataSource = dv;
subRepeater.DataBind();
}
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//DataRowView rowv = (DataRowView)e.Item.DataItem;
//string strClassID = Convert.ToString(rowv["ClassID"]);
Label LabelID = (Label)e.Item.FindControl("Label1");
string parentID = LabelID.Text.ToString();//此岗位的ID号
string sql = "select A.*,B.PositionName from CandidateUser AS A,PositionTable AS B where A.WantPosition = B.ID and A.WantPosition = '" + parentID + "' order by A.UID asc"; //取出应聘此岗位的所有人员
DataSet ds = newdb.CommonDataSet(sql);
Repeater subRepeater = (Repeater)e.Item.FindControl("Repeater2");
subRepeater.DataSource = dv;
subRepeater.DataBind();
}