The effect chart is as follows:
The source code is as follows:
Copy Code code 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 Repeater1_itemcommand (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 Repeater1_itemdatabound (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 ();
}
}
}
}
File package Download Repeatertest.rar
A comrade who is useful can refer to.