DataTable中DataColumn中的列 [英] Column within a DataColumn in DataTable

查看:188
本文介绍了DataTable中DataColumn中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序中创建一个gridview,用于导出excel中的数据。

我的表格如下所示:

-------- -------------------------------------------------- -----

|  S.No.   |   员工姓名   |                  总薪资              |

------------- -------------------------------------------------- -

                    &NBSP ;                         |基本工资| HRA |其他|总计   |



如何在另一个DataColumns中输入列。我的代码看起来是这样的uptil现在

<预LANG = C#> <跨度类= 代码关键字>私有的GridView GetExcelList(列表与LT; EmployeeDetails> lstapplications)
{
DataTable dt = new DataTable();
GridViewRow row = new GridViewRow( 0 1 ,DataControlRowType.Header,DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
dt.Columns.Add( S.No。);
dt.Columns.Add( 员工姓名);
dt.Columns.Add( Total Salary);
cell.Text = 要发布的总金额(以卢比计算);
cell.Horizo​​ntalAlign = Horizo​​ntalAlign.Center;
cell.ColumnSpan = 3 ;
row.Cells.Add(cell);

// 将数据输入列


GridView gridclone = new GridView();
gridclone.HeaderRow.Parent.Controls.AddAt(gridclone.Controls [<跨度类= 代码位> 0 ] Controls.Count - <跨度类= 代码位> 1 ,row);
gridclone.DataSource = dt;
gridclone.DataBind();
return gridclone;
}



当我运行代码并尝试将数据导出到excel时,我在行上出现空异常错误

'预郎= C#> gridclone.HeaderRow.Parent.Controls.AddAt(gridclone.Controls [<跨度类= 代码位> 0 ] Controls.Count - <跨度类=代码-digit> 1 ,row);



有没有人知道,为什么???

解决方案
我想你想是这样的一个 GridView的列标题合并在ASP.NET [ ^ ]


I need to create a gridview in my application for Export the data in excel.
my table looks like as below:
---------------------------------------------------------------
|  S.No.  |   Employee Name   |                   Total Salary              |
----------------------------------------------------------------
                                             | Basic Pay | HRA | Other | Total  |

How do i enter Columns inside another DataColumns. my code looks like this uptil now

private GridView GetExcelList(List<EmployeeDetails> lstapplications)
{
DataTable dt = new DataTable();
GridViewRow row = new GridViewRow(0, 1, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
dt.Columns.Add("S.No.");
dt.Columns.Add("Employee Name");
dt.Columns.Add("Total Salary");
cell.Text = "Total amount to be released (in Rs.)";
cell.HorizontalAlign = HorizontalAlign.Center;
cell.ColumnSpan = 3;
           row.Cells.Add(cell);
.
.//entering data into columns
.

GridView gridclone = new GridView();
gridclone.HeaderRow.Parent.Controls.AddAt(gridclone.Controls[0].Controls.Count - 1, row);
gridclone.DataSource = dt;
gridclone.DataBind();
return gridclone;
}


When i run the code and try to export the data to excel, i get a null exception error on the line

gridclone.HeaderRow.Parent.Controls.AddAt(gridclone.Controls[0].Controls.Count - 1, row);


does anyone has any idea, why???

解决方案

I think you want something like this one GridView column header merging in ASP.NET[^]


这篇关于DataTable中DataColumn中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆