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 網(wǎng)站性能優(yōu)化之緩字決 (上) 緩沖寫數(shù)據(jù)
通常情況下Asp.Net 網(wǎng)站的底層數(shù)據(jù)存儲都是關(guān)系數(shù)據(jù)庫,關(guān)系數(shù)據(jù)庫資源比較昂貴,而且也很容易造成瓶頸。緩字決文章就是為大家介紹如何有效使用緩存,異步寫緩沖數(shù)據(jù)庫的壓力,從而保證網(wǎng)站的性能。2010-06-06詳解CentOS 7.4下如何部署Asp.Net Core結(jié)合consul
這篇文章主要介紹了詳解CentOS 7.4下如何部署Asp.Net Core結(jié)合consul,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06asp.net異步獲取datatable并顯示的實現(xiàn)方法
這篇文章主要介紹了asp.net異步獲取datatable并顯示的實現(xiàn)方法,結(jié)合實例形式分析了asp.net一步操作datatable的相關(guān)技巧,需要的朋友可以參考下2016-03-03用類的繼承關(guān)系(重寫父類的方法)實現(xiàn)簡易后臺代碼模板
Asp.net的優(yōu)勢就在于快速構(gòu)建應(yīng)用,而對于一些最基礎(chǔ)數(shù)據(jù)的增刪改以及分頁事件或者樣式的設(shè)定可以通過在父類中寫上虛方法來供子類調(diào)用,接下來將為您測試一下用子類重寫父類的方法實現(xiàn)在模板的基礎(chǔ)上衍生變化2013-01-01Windows虛擬主機(jī)與VPS如何實現(xiàn)301重定向(asp.net)
301重定向應(yīng)該是研究SEO必須掌握的技術(shù)。如果你是剛接觸SEO的菜鳥,想了解什么是301重定向,請看《html實現(xiàn)301重定向的方法》一文,我在該篇隨筆中引用了Google網(wǎng)站站長工具對301重定向的解釋2011-12-12Asp.net SignalR創(chuàng)建實時聊天應(yīng)用程序
這篇文章主要介紹了Asp.net SignalR創(chuàng)建實時聊天應(yīng)用程序,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11