欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

asp.net Repeater显示父子表数据,无闪烁

时间:2020-10-10 11:45:39|栏目:.NET代码|点击:
效果图如下:


源代码如下:

复制代码 代码如下:

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();
}
}
}
}


文件打包下载RepeaterTest.rar
有用得着的同志可以参考..

上一篇:C#一个方法返回多个值示例

栏    目:.NET代码

下一篇:c#开发的程序安装时动态指定windows服务名称

本文标题:asp.net Repeater显示父子表数据,无闪烁

本文地址:http://www.codeinn.net/misctech/9192.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有