我在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
发布评论