admin 管理员组文章数量: 1184232
2024年3月8日发(作者:constellation 欧米茄)
前台页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile=""
Inherits="Test_TestTwoTable" %>
"/TR/xhtml1/DTD/">
后台页面代码:
using System;
using ;
using uration;
using tions;
using ;
using ty;
using ;
using trols;
using ts;
using ntrols;
public partial class Test_TestTwoTable :
{
protected void Page_Load(object sender, EventArgs e)
{
inScrollPositionOnPostBack = true;
if (!Back)
{
urce = GetData();
nd();
}
}
//获取数据部分
private DataTable GetData()
{
DataTable dt;
dt = new DataTable();
("Code");
("FName");
("MName");
("LName");
("Age");
("Elementary");
("Junior");
("High");
("Religion");
for (int i = 1; i <= 12; i++)
{
DataRow dr = ();
dr["Code"] = "Code" + ng();
dr["FName"] = "FName" + ng();
dr["MName"] = "MName" + ng();
dr["LName"] = "LName" + ng();
dr["Age"] = "Age" + ng();
dr["Elementary"] = "Elementary" + ng();
dr["Junior"] = "Junior" + ng();
dr["High"] = "High" + ng();
dr["Religion"] = "Religion" + ng();
(dr);
}
//为了实现自动隐藏功能,要在每个行的下面添加一个行,用于自动隐藏自表
DataTable OkTable = new DataTable();
(dt);//获取表结构和数据
();
//重新填充数据
for (int i = 0; i < ; i++)
{
DataRow 有效行 = ();
有效行["Code"] = [i]["Code"].ToString();
有效行["FName"] = [i]["FName"].ToString();
有效行["MName"] = [i]["MName"].ToString();
有效行["LName"] = [i]["LName"].ToString();
有效行["Age"] = [i]["Age"].ToString();
有效行["Elementary"] =
[i]["Elementary"].ToString();
有效行["Junior"] = [i]["Junior"].ToString();
有效行["High"] = [i]["High"].ToString();
有效行["Religion"] = [i]["Religion"].ToString();
(有效行);
DataRow 无效行 = ();
无效行["Code"] = "0";
无效行["FName"] = "0";
无效行["MName"] = "0";
无效行["LName"] = "0";
无效行["Age"] = "0";
无效行["Elementary"] = "0";
无效行["Junior"] = "0";
无效行["High"] = "0";
无效行["Religion"] = "0";
(无效行);
}
return OkTable;
}
//一定要在这个事件中重写,不然当回返后所重写的就会失效
int j = 0;
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e == w)
{
j = j + 1;
if (j % 2 == 0)
{
derMethodDelegate(new
RenderMethod(NewRenderMethod));
; e = false;
}
}
}
//所用重写的事件方法
public void NewRenderMethod(HtmlTextWriter writer, Control ctl)
{
("
TableCell cell = (TableCell)ls[7];
("colspan", "7");
("align", "center");
Control(writer);
}
//选择按扭
protected void GridView1_SelectedIndexChanging(object sender,
GridViewSelectEventArgs e)
{
GridViewRow ChildRow = [ectedIndex + 1];
if (e)
{
e = false;
}
else
{
e = true;
}
GridViewRow SelectedRow = [ectedIndex];
string ParentID = [1].Text;
(ParentID);
GridView g;
g = (GridView)ntrol("GridView2");
if (g == null)
{
(";没查找到GridView");
}
else
{
urce = ldData(ParentID); //模拟字表的内容
nd();
}
}
//模拟字表的内容
private DataTable GetChildData(string ParentID)
{
DataTable dt;
dt = new DataTable();
("Age");
("Elementary");
("Junior");
("High");
("Religion");
for (int i = 1; i <= 12; i++)
{
DataRow dr = ();
dr["Age"] = "Age" + ng();
dr["Elementary"] = "Elementary" + ng();
dr["Junior"] = "Junior" + ng();
dr["High"] = "High" + ng();
dr["Religion"] = "Religion" + ng();
(dr);
}
return dt;
}
}
版权声明:本文标题:GridView实现动态读取子表数据 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1709910944a549755.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论