datagrid嵌套和资源消耗
我这里参考的是以下两篇
http://www.cnblogs.com/lovecherry/archive/2005/04/26/145633.html
http://www.microsoft.com/china/MSDN/library/data/dataAccess/NestGridHierData.mspx
我只是做了datagrid的嵌套,并没有动态添加模板列那么复杂。
最后的代码给大家。有一部分是vs生成的,懒的写。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id=DataGrid1 runat="server" AutoGenerateColumns="False" DataSource="<%# dataSet1 %>">
<Columns>
<asp:BoundColumn DataField="EmployeeID" HeaderText="编号"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="测试列">
<ItemTemplate>
<asp:DataGrid id="DataGrid2" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="TerritoryID" HeaderText="编号"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:DataGrid id="DataGrid3" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="TerritoryID" HeaderText="标号"></asp:BoundColumn>
</Columns>
</asp:DataGrid></form>
</body>
</HTML>
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace test1
{
/**//// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.DataSet dataSet1;
protected System.Web.UI.WebControls.DataGrid DataGrid3;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
sqlDataAdapter1.Fill(dataSet1);
DataGrid3.DataSource=BindGrid2(1);
DataGrid1.DataBind();
DataGrid3.DataBind();
}
}
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet1 = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Employees", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("EmployeeID", "EmployeeID")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM Employees WHERE (EmployeeID = @Original_EmployeeID)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_EmployeeID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "EmployeeID", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=李征;packet size=4096;user id=fa;pwd=fa;data source=李征;persist secur" +
"ity info=False;initial catalog=Northwind";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Employees() VALUES (); SELECT EmployeeID FROM Employees WHERE (Employ" +
"eeID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT EmployeeID FROM Employees";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE Employees SET WHERE (EmployeeID = @Original_EmployeeID); SELECT EmployeeID" +
" FROM Employees WHERE (EmployeeID = @EmployeeID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_EmployeeID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "EmployeeID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@EmployeeID", System.Data.SqlDbType.Int, 4, "EmployeeID"));
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("zh-CN");
this.DataGrid1.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
}
#endregion
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
}
private DataView BindGrid2(int EmployeeID)
{
SqlConnection myconn=new SqlConnection();
myconn.ConnectionString="workstation id=李征;packet size=4096;user id=fa;pwd=fa;data source=李征;persist secur" +
"ity info=False;initial catalog=Northwind";
SqlDataAdapter myda=new SqlDataAdapter("select TerritoryID from EmployeeTerritories where EmployeeID="+EmployeeID.ToString(),myconn);
DataSet ds=new DataSet();
myda.Fill(ds);
return ds.Tables[0].DefaultView;
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DataGrid dgt = (DataGrid)e.Item.FindControl("DataGrid2");
dgt.DataSource=BindGrid2(int.Parse(e.Item.Cells[0].Text.ToString()));
dgt.DataBind();
//Label lb=(Label)e.Item.FindControl("l1");
//lb.Text="111";
}
}
}
}
挑重点看看吧。。。
再说到资源消耗,这么嵌套真有点资源杀手的味道。大部分资源都消耗在对控件的消耗上了。
真难想象再象我引用文章那样的给嵌套的dtatgrid在动态创建列会怎样。
转载于:https://www.cnblogs.com/jpwar/archive/2005/09/14/236451.html
datagrid嵌套和资源消耗相关推荐
- oracle高资源消耗sql,oracle 中如何定位重要(消耗资源多)的SQL
在分析SQL性能的时候,经常需要确定资源消耗多的SQL,总结如下: 1查看值得怀疑的SQL selectsubstr(to_char(s.pct,'99.00'),2)||'%'load, s.exe ...
- oracle高资源消耗sql,Oracle中定位重要(消耗资源多)的SQL
在分析SQL性能的时候,经常需要确定资源消耗多的SQL,总结如下: 1 查看值得怀疑的SQLselect substr(to_char(s.pct, 在分析SQL性能的时候,经常需要确定资源消耗多的S ...
- oracle高资源消耗sql,Oracle高资源消耗SQL语句定位
Oracle SQL语句资源消耗监控最常用的系统视图有v$sql.v$sqlarea.v$sqltext和v$session.本文我们先了解这些视图的作用与区别,然后了解如何定位高资源消耗SQL语句, ...
- 案例分析:倾斜值传入导致 SQL 资源消耗升高
作者 | 邓秋爽:云和恩墨技术工程师,有超过七年超大型数据库专业服务经验,擅长 Oracle 数据库优化.SQL 优化和 Troubleshooting. 局方监控系统反馈 2014-12-31 19 ...
- oracle view使用次數,oracle sql资源消耗相关视图
一.常用视图说明 Oracle sql语句资源消耗监控,最常用的系统视图有: v$sql v$sqlarea v$sqltext v$session v$sql和v$sqlarea基本相同,记录了共享 ...
- DataGrid 嵌套DataList
//DataGrid 嵌套DataList //第一层DataGrid private void LoadData(DataGrid p_DataGrid) { SystemTypeF ...
- 使用JavaCV实现海康rtsp转rtmp实现无插件web端直播(无需转码,低资源消耗)
使用JavaCV实现海康rtsp转rtmp实现无插件web端直播(无需转码,低资源消耗) 目录结构 添加依赖,编写配置文件 创建Bean 创建缓存Cache 修改启动类 拉流.推流.转封装 定时任务T ...
- Oracle一条资源消耗较高但是Executions=0的问题排查...
日常巡检某客户生产环境数据库时,发现AWR报告中有资源消耗较高但是Executions=0的现象: 这个现象可以解释为在这一个小时的快照周期内SQL一次都没执行完成. (一) 对第一条 SQLID=1 ...
- GPU 资源消耗原因和解决方案:
GPU 资源消耗原因和解决方案: GPU能干的事情比较单一:接收提交的纹理Texture
最新文章
- 情感分析研究的新视野
- EWS 通过SubscribeToPullNotifications订阅Exchange新邮件提醒
- python基础一循环
- 递归--整数划分问题
- 【C】@程序员,我们送给你一个成熟的Excel导入导出组件
- 移除集合效率高还是add高_List、set集合接口分析
- 接口可以继承抽象类吗_Python接口类的多继承以及抽象类的单继承
- 数仓中的星型模型和雪花模型
- java ceilingentry_java.util.TreeMap.ceilingKey()方法实例
- 根据文件路径打开文件所在文件夹,并且默认选中该文件
- Android中设置位移动画的停止
- 算法导论(原书第三版)答案与学习笔记(一)
- js算法 字母大小写转换
- 7-4 疯狂星期四!!!!!
- 【子网,超网和掩码】
- WPF 实现无边框窗口两种方法
- element UI 学习
- 中国象棋对局软件设计(四)[完]
- 案例—考勤后台管理系统需求
- Latex中的特殊符号