国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

dataGrid 多維表頭、表頭跨行跨列設計及綁定數據

2024-07-10 13:23:29
字體:
來源:轉載
供稿:網友
dataGrid 其實就是一個html table 
想清楚這個以后,要設置多維表頭就好辦了
html代碼

復制代碼 代碼如下:


<asp:DataGrid runat="server"
onitemdatabound="DataGrid1_ItemDataBound">
</asp:DataGrid>


然后綁定數據

復制代碼 代碼如下:


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;
}
}


效果圖

dataGrid 多維表頭、表頭跨行跨列設計及綁定數據

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 上栗县| 宾川县| 额尔古纳市| 台湾省| 黔西县| 义马市| 肥西县| 栾城县| 桓仁| 青田县| 延长县| 会泽县| 永仁县| 息烽县| 渝北区| 固阳县| 富源县| 长春市| 二手房| 崇阳县| 耿马| 渑池县| 石阡县| 聂荣县| 喜德县| 土默特右旗| 松原市| 奉化市| 营口市| 阳高县| 平山县| 北海市| 隆化县| 博乐市| 仲巴县| 洪泽县| 南澳县| 商洛市| 桂平市| 社旗县| 弋阳县|