some time ago, Insus.NET been demonstrated GridView control Header header row or column: " GridView control dynamically change the column name " and " Dynamic Merge Header header or custom GridView control certain columns ", now want to demonstrate the combined Gridview columns in a DataRow.
actually merge column is nothing complex problem, just understand the principle, I felt extremely simple.
database aspects of the preparation, in this case skipped.
create a web page in the site, to pull the GridView control. aspx page, and display data using a custom template. As follows:
go. aspx.cs the code behind write data binding code:
< br />
page in the browser, you'll see the following effects:
see whether the figure above the second column, there are KindName same order interface is simple and clear, Insus.NET decided to merge them. In order to achieve the data column of the row merge, we need to write a GridView control event OnRowCreated = "GridViewFruit_RowCreated":
Now, we can go to code behind write programs, and in writing OnRowCreated event procedure before you need to define a page-level variables:
image above variables, rowCount will record the total number of all records, the initial value is 0. rowindex row index is used to record the initial value of 0, while mergeCellText variables are merged field name.
OK, let's start writing OnRowCreated event logic program:
image above:
# 35 lines of code, if not the data rows, will skip the following procedure.
# 37 rows into the e.Row.DataItem DataRowView.
# 39 - # 43 lines of code, if it is the first row DataRow, the row index and column values will be merged record.
# 45 - # 62 lines of code are dealing with non-first data row.
# 47 lines of code, if you need to merge the data in the current row and column values are not the same as the previous line, we can merge the data columns in front of it. Also the current row index and column values recorded.
# 55 rows of the same column removed.
# 57 lines of code to determine whether the last line.
# 59 lines of code to do the last merge columns.
operating results are as follows:
< br /> If you understand the logic of the above approach, doing other columns merger is a breeze.
没有评论:
发表评论