dataGrid 多维表头、表头跨行跨列设计及绑定数据
绍兴新闻,lol视频录制,优岛网
datagrid 其实就是一个html table
想清楚这个以后,要设置多维表头就好办了
html代码
<asp:datagrid id="datagrid1" 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;
}
}
效果图
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论