This is a migrated thread and some comments may be shown as answers.

Databinding and GroupFooter issue

5 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bin
Top achievements
Rank 1
Bin asked on 02 Jul 2008, 12:21 AM

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

5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 03 Jul 2008, 12:01 PM
Hello Bin,

Could you please try setting AutoGenerateColumns="true" for RadGrid and see if this solves the problem. Also, please rename the RadGrid object created on the page, as its ID="RadGrid" is the same as the class name for the RadGrid object, just to make sure no naming conflicts arise when addressing either the instance, or the class.

Greetings,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bin
Top achievements
Rank 1
answered on 04 Jul 2008, 05:42 AM

I tried both, still get the same error:
Column 'ProductName' does not belong to table .

0
Veli
Telerik team
answered on 07 Jul 2008, 12:19 PM
Hi Bin,

I recognized that RadGrid does not have AutoGenerateColumn="true". Please set this property for both RadGrid and its MasterTableView and see if this works for you.

All the best,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bin
Top achievements
Rank 1
answered on 07 Jul 2008, 11:14 PM
I put the autogeneratecolumns=true  in the radgrid and mastertableview
but still give me the same error
0
Veli
Telerik team
answered on 08 Jul 2008, 12:19 PM
Hello Bin,

This is a strange behavior, and we need to identify is it RadGrid or the data connection that fails. Please consider setting up an SqlDataSource object (introduced in ASP.NET 2.0) with the northwind database files you are working with. After properly setting up and making sure SqlDataSource does return a ProductName column, bind RadGrid either using NeedDataSource event, or defining the DataSourceID in the aspx page.

Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Bin
Top achievements
Rank 1
Answers by
Veli
Telerik team
Bin
Top achievements
Rank 1
Share this question
or