日期:2014-05-18 浏览次数:20780 次
protected void Page_Load(object sender, EventArgs e) { this.type = "格式二"; this.sql = "select * from Hardware where " + this.Label1.Text.ToString().Trim() + " is not null or " + this.Label1.Text.ToString().Trim() + " <> ''"; InforReport nrr = new MISOA.SQLServerDAL.InforReport(sql, type); GridView3.DataSource = nrr.GetDataSetByadminInfor(); GridView3.DataBind(); } protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { }
int i; public DataSet GetDataSetByadminInfor() { string sqlname = "select name from syscolumns where id=object_id('Hardware')"; DataSet DB = SqlHelper.ExecuteReaderSelectToDataSet(SqlHelper.CreateConnection(), sqlname); DataSet DBds = SqlHelper.ExecuteReaderSelectToDataSet(SqlHelper.CreateConnection(), sql); DataSet ds = new DataSet(); DataTable dt = new DataTable("VIEW"); DataTable dt2 = new DataTable("Columns"); ds.Tables.Add(dt); DataSet ds2 = new DataSet(); ds2.Tables.Add(dt2); for (int k = 0; k < DB.Tables[0].Rows.Count; k++) { this.Name = DB.Tables[0].Rows[k][0].ToString().Trim(); dt.Columns.Add(Name, typeof(string)); } try { for (int j = 0; j < DBds.Tables[0].Rows.Count; j++) { DataRow dr = ds.Tables["VIEW"].NewRow(); for (i = 0; i < DB.Tables[0].Rows.Count; i++) { Name = DB.Tables[0].Rows[i][0].ToString(); dr[Name] = DBds.Tables[0].Rows[j][i].ToString(); } ds.Tables["VIEW"].Rows.Add(dr); } return ds; } catch (Exception e2) { return ds; } }
<asp:GridView ID="GridView3" runat="server" EmptyDataText="无数据" Font-Size="Small" AllowPaging="True" OnSelectedIndexChanging="GridView3_SelectedIndexChanging"> <PagerTemplate> <table width="100%"> <tr> <td style="text-align:right"> 第 <asp:Label id="lblPageIndex" runat="server" text=' <%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页 共/ <asp:Label id="lblPageCount" runat="server" text=' <%# ((GridView)Container.Parent.Parent).PageCount %>' />页 <asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" /> <asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />