网格视图中的自定义列. [英] Customized column in the grid view.
问题描述
我正在创建报告并将其绑定到网格视图中以进行显示.这是带有示例数据的表格,我们在其中绑定网格:-
I am creating a report and binding it in a grid View for Display Purpose.This is the table with Sample Data from where we are binding the grid :-
UseID CountyGroupname ProjectName Duration
1 NJ Middlesex 10
2 California Passaic 20
3 NJ Rockland 10
4 California New Castle 40
5 Alaska Maricopa 50
精确网格应显示为:-
The Exact Grid should be displayed like this :-
NJ California Alaska
UserID MiddleSex Rockland Passaic New Castle Maricopa Total
1 10 0 0 0 0 10
2 0 0 20 0 0 20
3 0 10 0 0 0 10
4 0 0 0 40 0 40
5 0 0 0 0 50 50
Total 10 10 20 40 50 130
我能够以这种格式创建报告,但无法像上面在网格视图中提到的那样绑定CountyGroupname.
用户ID MiddleSex Rockland
I am able to create the report in this format but not getting how I bind the CountyGroupname as mentioned above in the grid View.
UserID MiddleSex Rockland
Passaic New Castle Maricopa Total
1 10 0 0 0 0 10
2 0 0 20 0 0 20
3 0 10 0 0 0 10
4 0 0 0 40 0 40
5 0 0 0 0 50 50
Total 10 10 20 40 50 130
请注意,我正在使用SQl的Pivot方法创建此报表,并根据项目名称创建动态列".
Note that I am creating this report using Pivot method of SQl and creating Dynamic Columns as per the Projectname.
推荐答案
尝试以下操作
Try the following
protected void gvEmployee_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView oGridView = (GridView)sender;
GridViewRow oGridViewRow = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell oTableCell = new TableCell();
oTableCell.Text = "Employee Details";
oTableCell.ColumnSpan = gvEmployee.Columns.Count;
oGridViewRow.Cells.Add(oTableCell);
oTableCell.CssClass = "header";
oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);
}
}
上面的代码将在现有gridview标头的顶部创建另一个标头.
应用逻辑并编写必要的代码
希望对您有帮助
The above code will create another header on top of the existing gridview header.
Apply your logic and write the necessary code
Hope this helps
这篇关于网格视图中的自定义列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!