将计算列添加到Datagrid

编程入门 行业动态 更新时间:2024-10-25 17:19:49
本文介绍了将计算列添加到Datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在C#中有一个基于SQL查询的绑定数据网格。 结果显示在Sharepoint 2003 Webpart中。 我想添加一个新的列基于datagrid中两个 列的结果。 我不可能在SQL查询中执行此操作 我正在使用的数据提供程序不支持列别名。 例如将这些列的结果放入一个新列。 newColumn = new BoundColumn(); newColumn.DataField =" pt_desc1" ;; newColumn.HeaderText =" Description"; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField =" pt_desc2"; newColumn.HeaderText =" Description" ;; OrdersGrid.Columns.Add(newColumn) ; - GML

I have a bound datagrid in C# based on an an SQL query. The results are displayed in a Sharepoint 2003 Webpart. I would like to add a new column based on the results of two columns in the datagrid. It is not possible for me to do this within the SQL query as the data provider I am using does not support column alias''s. e.g. Put the results of these columns into a new column. newColumn = new BoundColumn(); newColumn.DataField = "pt_desc1"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField = "pt_desc2"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn); -- GML

推荐答案

您可以使用DataColumn.Expression属性来将计算的 属性添加到DataGrid。 例如。你可以使用 DataColumn resultColumn = new DataColumn(); resultColumn.Expression =" pt_dec1 + pt_desc2" ;; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML写道: You can use the DataColumn.Expression property to add a calculated property to the DataGrid. For eg. you can use DataColumn resultColumn = new DataColumn(); resultColumn.Expression = "pt_dec1+pt_desc2"; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML wrote: 我在C#中有一个基于SQL查询的绑定数据网格。结果显示在Sharepoint 2003 Webpart中。我想要根据数据网格中两个列的结果添加一个新列。我不可能在SQL查询中执行此操作,因为我使用的数据提供程序没有支持列别名'。 例如将这些列的结果放入一个新列。 newColumn = new BoundColumn(); newColumn.DataField =" pt_desc1"; newColumn.HeaderText =" Description" ;; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField =" pt_desc2"; newColumn.HeaderText ="描述" ;; OrdersGrid.Columns.Add(newColumn); I have a bound datagrid in C# based on an an SQL query. The results are displayed in a Sharepoint 2003 Webpart. I would like to add a new column based on the results of two columns in the datagrid. It is not possible for me to do this within the SQL query as the data provider I am using does not support column alias''s. e.g. Put the results of these columns into a new column. newColumn = new BoundColumn(); newColumn.DataField = "pt_desc1"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField = "pt_desc2"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn);

此外,还有一个很好的话题在帮助中的DataColumn.Expression 文件。 - Miha Markic [MVP C#] - RightHand .NET咨询与开发 miha at rthand com www.rthand " Sijin Joseph" < SI *************** @ hotmail>在消息中写道 news:un ************** @ TK2MSFTNGP10.phx.gbl ... In addition, there is a good topic on DataColumn.Expression in help files. -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand "Sijin Joseph" <si***************@hotmail> wrote in message news:un**************@TK2MSFTNGP10.phx.gbl... 您可以使用DataColumn .Expression属性将计算的属性添加到DataGrid。 例如。你可以使用 DataColumn resultColumn = new DataColumn(); resultColumn.Expression =" pt_dec1 + pt_desc2"; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML写道: You can use the DataColumn.Expression property to add a calculated property to the DataGrid. For eg. you can use DataColumn resultColumn = new DataColumn(); resultColumn.Expression = "pt_dec1+pt_desc2"; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML wrote: I基于SQL查询在C#中绑定数据网格。结果显示在Sharepoint 2003 Webpart中。我想根据两个列的结果添加一个新列在数据网格中。我不可能在SQL查询中执行此操作,因为我使用的数据提供程序不支持列别名。 例如将这些列的结果放入一个新列。 newColumn = new BoundColumn(); newColumn.DataField =" pt_desc1"; newColumn.HeaderText =" Description" ;; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField =" pt_desc2"; newColumn.HeaderText =" Description"; OrdersGrid.Columns.Add(newColumn); I have a bound datagrid in C# based on an an SQL query. The results are displayed in a Sharepoint 2003 Webpart. I would like to add a new column based on the results of two columns in the datagrid. It is not possible for me to do this within the SQL query as the data provider I am using does not support column alias''s. e.g. Put the results of these columns into a new column. newColumn = new BoundColumn(); newColumn.DataField = "pt_desc1"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn); newColumn = new BoundColumn(); newColumn.DataField = "pt_desc2"; newColumn.HeaderText = "Description"; OrdersGrid.Columns.Add(newColumn);

你应该添加列到数据源,在你的情况下是DataTable。 - Miha Markic [MVP C#] - RightHand .NET咨询&开发 miha at rthand com www.rthand " GML" < GM*@discussions.microsoft>在消息中写道 news:50 ********************************** @ microsof t ... You should add the column to datasource, in your case to DataTable. -- Miha Markic [MVP C#] - RightHand .NET consulting & development miha at rthand com www.rthand "GML" <GM*@discussions.microsoft> wrote in message news:50**********************************@microsof t... 嗨Sijin, 谢谢你,但我如何将新的colum添加到我的网格中。 我得到了如果我使用错误: - DataColumn resultColumn = new DataColumn(); resultColumn.Expression =" pt_dec1 + pt_desc2" ;; resultColumn.ColumnName =" Part Description" ;; OrdersGrid.Columns.Add(resultColumn); " Sijin Joseph"写道: Hi Sijin, Thanks for that but how do i add the new colum to my grid. I get an error if i use :- DataColumn resultColumn = new DataColumn(); resultColumn.Expression = "pt_dec1+pt_desc2"; resultColumn.ColumnName = "Part Description"; OrdersGrid.Columns.Add(resultColumn); "Sijin Joseph" wrote: 您可以使用DataColumn.Expression属性将计算的属性添加到DataGrid。 例如。你可以使用 DataColumn resultColumn = new DataColumn(); resultColumn.Expression =" pt_dec1 + pt_desc2"; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML写道: You can use the DataColumn.Expression property to add a calculated property to the DataGrid. For eg. you can use DataColumn resultColumn = new DataColumn(); resultColumn.Expression = "pt_dec1+pt_desc2"; Sijin Joseph www.indiangeek weblogs.asp/sjoseph GML wrote: > ;我在C#中有一个基于SQL查询的绑定数据网格。>结果显示在Sharepoint 2003 Webpart中。>我想根据两个结果添加一个新列>数据网格中的列。>我无法在SQL查询中执行此操作,因为>我正在使用的数据提供程序不支持列别名'> >例如将这些列的结果放入新列。> > newColumn = new BoundColumn(); > newColumn.DataField =" pt_desc1"; > newColumn.HeaderText =" Description"; > OrdersGrid.Columns.Add(newColumn); > > newColumn = new BoundColumn(); > newColumn.DataField =" pt_desc2"; > newColumn.HeaderText =" Description"; > OrdersGrid.Columns.Add(newColumn); > > > I have a bound datagrid in C# based on an an SQL query. > The results are displayed in a Sharepoint 2003 Webpart. > I would like to add a new column based on the results of two > columns in the datagrid. > It is not possible for me to do this within the SQL query as > the data provider I am using does not support column alias''s. > > e.g. Put the results of these columns into a new column. > > newColumn = new BoundColumn(); > newColumn.DataField = "pt_desc1"; > newColumn.HeaderText = "Description"; > OrdersGrid.Columns.Add(newColumn); > > newColumn = new BoundColumn(); > newColumn.DataField = "pt_desc2"; > newColumn.HeaderText = "Description"; > OrdersGrid.Columns.Add(newColumn); > >

更多推荐

将计算列添加到Datagrid

本文发布于:2023-10-31 07:51:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545488.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Datagrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!