dataGrid 多維表頭、表頭跨行跨列設(shè)計及綁定數(shù)據(jù)
更新時間:2012年12月20日 14:53:29 作者:
dataGrid 其實就是一個html table,本文將介紹dataGrid 多維表頭,表頭跨行跨列設(shè)計方法需要了解的朋友可以參考下
dataGrid 其實就是一個html table
想清楚這個以后,要設(shè)置多維表頭就好辦了
html代碼
<asp:DataGrid ID="DataGrid1" runat="server"
onitemdatabound="DataGrid1_ItemDataBound">
</asp:DataGrid>
然后綁定數(shù)據(jù)
protected void Page_Load(object sender, EventArgs e)
{
string strsql = "select EmpID, Name, BranchID, LoginID, Pwd, Sex, EmpCode, Email, OfficeTel from mrBaseInf";
SqlConnection con = new SqlConnection("server=.;database=iOffice2009;uid=sa;pwd=sa");
DataSet ds = new DataSet();
SqlDataAdapter ter = new SqlDataAdapter(strsql, con);
con.Open();
ter.Fill(ds);
con.Close();
this.DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
接下來添加DataGrid1_ItemDataBoun事件
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType==ListItemType.Header)
{
e.Item.Cells[0].RowSpan = 2;
e.Item.Cells[1].RowSpan = 2;
e.Item.Cells[2].RowSpan = 2;
e.Item.Cells[3].RowSpan = 2;
e.Item.Cells[4].RowSpan = 2;
e.Item.Cells[5].ColumnSpan = 4;
e.Item.Cells[5].HorizontalAlign = HorizontalAlign.Center;
e.Item.Cells[5].Text = "測試</td></tr><tr><td>列1</td><td>列2</td><td>列3</td><td>列4</td></tr>";
e.Item.Cells[6].Visible = false;
e.Item.Cells[7].Visible = false;
e.Item.Cells[8].Visible = false;
}
}
效果圖
想清楚這個以后,要設(shè)置多維表頭就好辦了
html代碼
復(fù)制代碼 代碼如下:
<asp:DataGrid ID="DataGrid1" runat="server"
onitemdatabound="DataGrid1_ItemDataBound">
</asp:DataGrid>
然后綁定數(shù)據(jù)
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
string strsql = "select EmpID, Name, BranchID, LoginID, Pwd, Sex, EmpCode, Email, OfficeTel from mrBaseInf";
SqlConnection con = new SqlConnection("server=.;database=iOffice2009;uid=sa;pwd=sa");
DataSet ds = new DataSet();
SqlDataAdapter ter = new SqlDataAdapter(strsql, con);
con.Open();
ter.Fill(ds);
con.Close();
this.DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
接下來添加DataGrid1_ItemDataBoun事件
復(fù)制代碼 代碼如下:
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType==ListItemType.Header)
{
e.Item.Cells[0].RowSpan = 2;
e.Item.Cells[1].RowSpan = 2;
e.Item.Cells[2].RowSpan = 2;
e.Item.Cells[3].RowSpan = 2;
e.Item.Cells[4].RowSpan = 2;
e.Item.Cells[5].ColumnSpan = 4;
e.Item.Cells[5].HorizontalAlign = HorizontalAlign.Center;
e.Item.Cells[5].Text = "測試</td></tr><tr><td>列1</td><td>列2</td><td>列3</td><td>列4</td></tr>";
e.Item.Cells[6].Visible = false;
e.Item.Cells[7].Visible = false;
e.Item.Cells[8].Visible = false;
}
}
效果圖
相關(guān)文章
ASP.NET通用權(quán)限驗證的實現(xiàn)代碼思路
這篇文章主要介紹了ASP.NET通用權(quán)限驗證的實現(xiàn)代碼思路,需要的朋友可以參考下2015-12-12
asp.net 在線編輯word文檔 可保存到服務(wù)器
使用說明:該方法只在office xp 和 2003上 測試通過,2000及以下 版本沒試。2010-01-01
ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設(shè)置(九)
這篇文章主要為大家詳細(xì)介紹了ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設(shè)置,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
利用Asp.Net Core的MiddleWare思想如何處理復(fù)雜業(yè)務(wù)流程詳解
這篇文章主要給大家介紹了關(guān)于利用Asp.Net Core的MiddleWare思想如何處理復(fù)雜業(yè)務(wù)流程的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起看看吧2018-08-08
Ext.net中的MessageBox的簡單應(yīng)用實現(xiàn)代碼
今天在項目中要用到簡單的MessageBox的使用。在Ext.net中沒有Winform那么簡單,直接寫MessageBox.show()的方法。于是就去examples.ext.net的例子網(wǎng)站找,想找到個實際能用的2012-03-03
.Net極限生產(chǎn)力之分表分庫全自動化Migrations?Code-First
這篇文章主要介紹了.Net極限生產(chǎn)力之分表分庫全自動化Migrations?Code-First,輕量級針對分表分庫讀寫分離的解決方案,具有零依賴、零學(xué)習(xí)成本、零業(yè)務(wù)代碼入侵適配2022-07-07

