Hi, I am just using the radgrid to show the data from a dynamic datasource, everything is ok except when I enable the aggregrate function for the autogenerated columns it gives me the error "Column 'xxxx' not belong to the table", below is my C#code:
using System; | |
using System.Data; | |
using System.Configuration; | |
using System.Collections; | |
using System.Web; | |
using System.Web.Security; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using System.Web.UI.WebControls.WebParts; | |
using System.Web.UI.HtmlControls; | |
using Telerik.Web.UI; | |
using System.Data.SqlClient; | |
public partial class test : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
protected void RadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) | |
{ | |
this.RadGrid.DataSource = GetReportDataset() ; | |
} | |
private DataSet GetReportDataset() | |
{ | |
SqlConnection sqlconn = new SqlConnection(); | |
sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings["NorthWind"].ConnectionString; | |
SqlCommand sqlcomm = new SqlCommand("select CategoryID,ProductName,UnitPrice,UnitsInStock,UnitsInStock From Northwind.dbo.Products", sqlconn); | |
sqlcomm.CommandType = CommandType.Text; | |
DataSet ds = new DataSet(); | |
SqlDataAdapter adapter = new SqlDataAdapter(); | |
adapter.SelectCommand = sqlcomm; | |
sqlconn.Open(); | |
adapter.Fill(ds); | |
sqlconn.Close(); | |
return ds; | |
} | |
protected void show_Click(object sender, EventArgs e) | |
{ | |
this.RadGrid.Rebind(); | |
this.RadGrid.Visible = true; | |
} | |
protected void RadGrid_ColumnCreated(object sender, GridColumnCreatedEventArgs e) | |
{ | |
if (e.Column is GridBoundColumn) | |
{ | |
GridBoundColumn col = (GridBoundColumn)e.Column; | |
if (col.DataField != "Group" && col.DataField != "Store") | |
{ | |
col.Aggregate = GridAggregateFunction.Sum; | |
} | |
} | |
} | |
} | |
and aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> | |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="Telerik" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head id="Head1" runat="server"> | |
<title>Untitled Page</title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<asp:ScriptManager ID="ScriptManager1" runat="server"> | |
</asp:ScriptManager> | |
<div id="test" visible="false"> | |
<Telerik:RadAjaxManager EnableAJAX="true" ID="ajax1" runat="server"> | |
<AjaxSettings> | |
<Telerik:AjaxSetting AjaxControlID="RadGrid"> | |
<UpdatedControls> | |
<Telerik:AjaxUpdatedControl ControlID="RadGrid" /> | |
</UpdatedControls> | |
</Telerik:AjaxSetting> | |
</AjaxSettings> | |
</Telerik:RadAjaxManager> | |
<Telerik:RadGrid ID="RadGrid" runat="server" AllowPaging="True" AllowSorting="True" OnColumnCreated="RadGrid_ColumnCreated" | |
GridLines="None" Height="361px" OnNeedDataSource="RadGrid_NeedDataSource" ShowFooter="false" | |
ShowGroupPanel="false" PageSize="50" Width="100%" Visible="false"> | |
<ClientSettings> | |
<Scrolling AllowScroll="True" FrozenColumnsCount="2" UseStaticHeaders="True" /> | |
</ClientSettings> | |
<MasterTableView ShowGroupFooter="true" GroupLoadMode="Client" TableLayout="Auto"> | |
<Columns> | |
</Columns> | |
<GroupByExpressions> | |
<Telerik:GridGroupByExpression> | |
<GroupByFields> | |
<Telerik:GridGroupByField FieldName="CategoryID" FieldAlias="CategoryID" HeaderText="CategoryID" /> | |
</GroupByFields> | |
<SelectFields> | |
<Telerik:GridGroupByField FieldName="CategoryID" FieldAlias="CategoryID" HeaderText="CategoryID" /> | |
</SelectFields> | |
</Telerik:GridGroupByExpression> | |
</GroupByExpressions> | |
<RowIndicatorColumn Visible="False"> | |
<HeaderStyle Width="20px" /> | |
</RowIndicatorColumn> | |
<ExpandCollapseColumn Resizable="False" Visible="False"> | |
<HeaderStyle Width="20px" /> | |
</ExpandCollapseColumn> | |
<EditFormSettings> | |
<PopUpSettings ScrollBars="None" /> | |
</EditFormSettings> | |
</MasterTableView> | |
<HeaderStyle Width="200px" /> | |
</Telerik:RadGrid> | |
<asp:Button ID="show" runat="server" Text="show grid" OnClick="show_Click" /></div> | |
</form> | |
</body> | |
</html> | |
when I enable the aggregate by using:
col.Aggregate = GridAggregateFunction.Sum;
it gives me error
"Column 'ProductName' does not belong to table"
in the RadGrid.Rebind();
anyone know why this happens?
Thx