As follows:
The source code is as follows:
Copy codeThe Code is as follows: using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Namespace RepeaterTest
{
Public partial class Repeater: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
This. bind ();
}
}
Private DataSet dataSource
{
Get
{
If (ViewState ["ds"]! = Null)
{
Return (DataSet) ViewState ["ds"];
}
Else
{
DataSet ds = DataSource. GetDataSet ();
ViewState ["ds"] = ds;
Return ds;
}
}
}
Private void bind ()
{
DataSet ds = this. dataSource;
This. Repeater1.DataSource = ds. Tables ["tbclass"];
This. Repeater1.DataBind ();
This. Repeater2.DataSource = ds. Tables ["tbclass"];
This. Repeater2.DataBind ();
}
Protected void repeaterincluitemcommand (object source, RepeaterCommandEventArgs e)
{
If (e. CommandName = "expand ")
{
LinkButton btn = (LinkButton) e. CommandSource;
GridView grid = (GridView) btn. Parent. FindControl ("grid1 ");
If (btn. Text = "+ ")
{
Btn. Text = "-";
Grid. Visible = true;
}
Else
{
Btn. Text = "+ ";
Grid. Visible = false;
}
}
}
Protected void repeaterincluitemdatabound (object sender, RepeaterItemEventArgs e)
{
DataTable dt = this. dataSource. Tables ["tbstu"];
LinkButton objButton = (LinkButton) e. Item. FindControl ("btnExpand ");
If (objButton! = Null & objButton. CommandArgument! = "")
{
String classID = objButton. CommandArgument;
Dt. DefaultView. RowFilter = "ClassID =" + classID;
DataTable dtStu = dt. DefaultView. ToTable ();
GridView grid = (GridView) e. Item. FindControl ("grid1 ");
Grid. DataSource = dtStu;
Grid. DataBind ();
}
}
Protected void Repeater2_ItemDataBound (object sender, RepeaterItemEventArgs e)
{
DataTable dt = this. dataSource. Tables ["tbstu"];
Label objlbl = (Label) e. Item. FindControl ("lblclassid ");
If (objlbl! = Null & objlbl. Text! = "")
{
String classID = objlbl. Text;
Dt. DefaultView. RowFilter = "ClassID =" + classID;
DataTable dtStu = dt. DefaultView. ToTable ();
GridView grid = (GridView) e. Item. FindControl ("grid2 ");
Grid. DataSource = dtStu;
Grid. DataBind ();
}
}
}
}
Package and download repeatertest.rar
Useful comrades can refer ..