admin 管理员组

文章数量: 1184232


2024年3月8日发(作者:constellation 欧米茄)

前台页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile=""

Inherits="Test_TestTwoTable" %>

"/TR/xhtml1/DTD/">

无标题页

AutoGenerateColumns="False" Font-Size="14px"

Width="589px" OnRowCreated="GridView1_RowCreated"

OnSelectedIndexChanging="GridView1_SelectedIndexChanging">

ShowSelectButton="True" />

HeaderText="Code" />

HeaderText="FName" />

HeaderText="MName" />

HeaderText="LName" />

HeaderText="Age" />

HeaderText="Elementary" />

runat="server" Width="555px" >

后台页面代码:

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)

{

(" n");

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;

}

}


本文标签: 重写 数据 页面 代码