华域联盟 .Net dataGrid 多维表头、表头跨行跨列设计及绑定数据

dataGrid 多维表头、表头跨行跨列设计及绑定数据

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;

}

}

效果图

您可能感兴趣的文章:

  • asp.net DataGrid 中文字符排序的实现代码
  • DataGrid 动态添加模板列 实现代码
  • asp.net DataGrid控件中弹出详细信息窗口
  • 如何在DataGrid控件中实现自定义分页
  • ASP.NET中为DataGrid添加合计字段
  • DataGrid使用心得(调用及连接数据库等等)

本文由 华域联盟 原创撰写:华域联盟 » dataGrid 多维表头、表头跨行跨列设计及绑定数据

转载请保留出处和原文链接:https://www.cnhackhy.com/45423.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部