Merge Same Data Column in Gridview
来源:互联网 发布:央视直播软件哪个好 编辑:程序博客网 时间:2024/06/13 05:03
In this article I use an OnRowDataBound event of GridView and use RowSpan of cells.
In this article I connect with a SQL database & in the table is a college description. College name with branch wise .. both colleges have many branches so I merge college name like this:
on Aspx page
In the aspx page add a GridView Control then add a SqldataSource. Configure the database with a college table and a fill for the GridView. All data is shown in the GridView. Add an event to the GridView:
OnRowDataBound="GridView1_RowDataBound"
In the aspx.cs page write the following code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{ //We're only interested in Rows that contain data
//get a reference to the data used to databound the row
DataRowView drv = ((DataRowView)e.Row.DataItem);
if (previousCat == drv["Collegename"].ToString())
{
//If it's the same category as the previous one
//Increment the rowspan
if (GridView1.Rows[firstRow].Cells[0].RowSpan == 0)
GridView1.Rows[firstRow].Cells[0].RowSpan = 2;
else
GridView1.Rows[firstRow].Cells[0].RowSpan += 1;
//Remove the cell
e.Row.Cells.RemoveAt(0);
}
else //It's a new category
{ //Set the vertical alignment to top
e.Row.VerticalAlign = VerticalAlign.Top;
//Maintain the category in memory
previousCat = drv["Collegename "].ToString();
firstRow = e.Row.RowIndex;
}
}
}
Then you run your page & see the merged data in the GridView.
Conclusion
In this article I tried to solve the problem of merging columns in a GridView. Hopefully it's working for you too.
- Merge Same Data Column in Gridview
- javascript sort table & merge same column
- merge two column into one field in sql and hql
- Transformer入门教程(十一)(TR2703) A column in data source
- Using MERGE in SQL Server to insert, update and delete at the same time
- how to merge array of hash based same keys in ruby?
- Mail merge region 'tablePrint' is badly formed. TableStart and TableEnd should be in the same sectio
- angular-ui-grid merge cells in column(合并列上的单元格)
- GridView column的隐藏
- 建立GridView Column
- [gridview] -- Column源码
- FSharp.Data.SqlClient: Seamlessly integrating T-SQL and F# in the same code
- How to get Hidden Column Value in GridView(ASP.net GridView如何获取隐藏列的值)
- Same physical column represented by different logical column names
- 82.Examine the data in the CUST_NAME column of the CUSTOMERS table.
- 83.Examine the data in the CUST_NAME column of the CUSTOMERS table.
- 101.Examine the data in the PROMO_BEGIN_DATE column of the PROMOTIONS table:
- sorting data based on the value in second column of a file
- round函数
- tabIndex 属性
- Duilib
- 关于html5的一些介绍
- Android的生命周期图
- Merge Same Data Column in Gridview
- Android开发环境的搭建之二 VMware虚拟工具安装
- flash mask
- sql语句 Group By 小结
- 广州传智播客保证学生就业的六大策略
- 游戏中背景音乐循环播放
- 比亚迪(24.44,-1.28,-4.98%)启动了一个庞大的裁员计划
- 转 在UpdatePanel中GridView导出EXCEL问题
- JQuery 学习笔记(三) jQuery操作