Asp.net Repeater displays parent and child table data without blinking

Source: Internet
Author: User

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 ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.