动态地在网格视图行中设置Col范围? [英] Set Col span in grid view row dynamically?
本文介绍了动态地在网格视图行中设置Col范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个gridview,需要列才能拥有动态colspans ..我甚至可以添加它以及如何在c#中添加col跨度?
I got a gridview which needs columns to have dynamic colspans.. which even can I add this and how to add col spans in c# ?
推荐答案
protected void EmployeeGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
//Creating a gridview object
GridView objGridView = (GridView)sender;
//Creating a gridview row object
GridViewRow objgridviewrow = new GridViewRow(1, 0, DataControlRowType.Header, DataControlRowState.Insert);
//Creating a table cell object
TableCell objtablecell = new TableCell();
#region Merge cells
//Add a blank cell at the first three cell headers
//This can be achieved by making the colspan property of the table cell object as 3
// and the text property of the table cell object will be blank
//Henceforth, add the table cell object to the grid view row object
AddMergedCells(objgridviewrow, objtablecell, 3, "Employee Detail", System.Drawing.Color.LightGreen.Name);
//Merge columns d,e (i.e.Address, City, Region, Postal Code, Country) under the column name "Address Details"
//This can be achieved by making the colspan property of the table cell object as 2
//and setting it's text to "Address Details"
//Henceforth, add the table cell object to the grid view row object
AddMergedCells(objgridviewrow, objtablecell, 5, "Address Details", System.Drawing.Color.LightSkyBlue.Name);
//Lastly add the gridrow object to the gridview object at the 0th position
//Because,the header row position is 0.
objGridView.Controls[0].Controls.AddAt(0, objgridviewrow);
#endregion
}
}
这篇关于动态地在网格视图行中设置Col范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文