Sort "Cannot find column" error

11 posts, 0 answers
  1. Billy8988
    Billy8988 avatar
    13 posts
    Member since:
    Jul 2008

    Posted 09 Jul 2010 Link to this post

    My grid displays fine with all the valid data but once I click on one of the columns to sort, it crashes with the following call stack
    I have double checked SortExpression and DataField and they are same (pl. see below).  I do have bunch of nulls for data, but it seems to handle them in displaying. Any help would be greatly appreciated. Thanks

    [IndexOutOfRangeException: Cannot find column FILE_NAME.]
       System.Data.DataTable.ParseSortString(String sortString) +4826462
       System.Data.DataView.CheckSort(String sort) +32
       System.Data.DataView.set_Sort(String value) +128
       Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +4873
       Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +41
       Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +171
       Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +356
       Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +713
       System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
       System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
       Telerik.Web.UI.GridTableView.PerformSelect() +28
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
       Telerik.Web.UI.GridTableView.DataBind() +368
       Telerik.Web.UI.GridSortCommandEventArgs.ExecuteCommand(Object source) +326
       Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +191
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +61
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +165
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
       System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
       System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
    


    My aspx portion is here
    <telerik:RadGrid ID="ExcelGrid"  AutoGenerateColumns="false" EnableViewState="true"
                    Skin="Office2007"
                 AllowSorting="True"
                   AllowMultiRowSelection="false" runat="server" GridLines="None"
                   OnItemDataBound="ExcelGrid_ItemDataBound"
                   onneeddatasource="ExcelGrid_NeedDataSource">
                 <MasterTableView Width="100%" BorderWidth="0" TableLayout="Auto" DataKeyNames="FILE_NAME">
                 
                     <RowIndicatorColumn>
                         <HeaderStyle Width="20px" />
                     </RowIndicatorColumn>
                     <ExpandCollapseColumn>
                         <HeaderStyle Width="20px" />
                     </ExpandCollapseColumn>
                     <Columns>
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Row#">
                        <ItemStyle HorizontalAlign="left"/>
                       <ItemTemplate>
                        <asp:Label ID="numberLabel" runat="server"/>
                       </ItemTemplate>    
                       </telerik:GridTemplateColumn>             
                         <telerik:GridTemplateColumn DataField="FILE_NAME" HeaderText="File Name"
                             SortExpression="FILE_NAME" UniqueName="FILE_NAME">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                             <ItemTemplate>                            
                                 <a href='download.aspx?docID=<%# DataBinder.Eval(Container.DataItem, "FILE_NAME").ToString() %>'>
                                 <%# DataBinder.Eval(Container.DataItem, "FILE_NAME").ToString()%></a>
                             </ItemTemplate>
                         </telerik:GridTemplateColumn>
                         <telerik:GridBoundColumn DataField="Agreemt_Date" HeaderText="Agreement Date" DataFormatString="{0:dd/MM/yyyy}"
                             SortExpression="Agreemt_Date" UniqueName="Agreemt_Date">
                             <ItemStyle HorizontalAlign="left" Width="25" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Orig_Agmt_Type" HeaderText="Original Agreement Type"
                             SortExpression="Orig_Agmt_Type" UniqueName="Orig_Agmt_Type">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Mod_Agreemt_Type" HeaderText="Model Agreement Type"
                             SortExpression="Mod_Agreemt_Type" UniqueName="Mod_Agreemt_Type">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Parties" HeaderText="Parties"
                             SortExpression="Parties" UniqueName="Parties">
                             <ItemStyle HorizontalAlign="left" Width="50" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Basin" HeaderText="Basin"
                             SortExpression="Basin" UniqueName="Basin">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Municipality" HeaderText="Municipality"
                             SortExpression="Municipality" UniqueName="Municipality">
                             <ItemStyle HorizontalAlign="left" Width="75" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Sewershed_Area" HeaderText="Sewershed / Area"
                             SortExpression="Sewershed_Area" UniqueName="Sewershed_Area">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Source" HeaderText="Source"
                             SortExpression="Source" UniqueName="Source">
                             <ItemStyle HorizontalAlign="left" Width="122" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Status" HeaderText="Status"
                             SortExpression="Status" UniqueName="Status">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Notes" HeaderText="Notes"
                             SortExpression="Notes" UniqueName="Notes">
                             <ItemStyle HorizontalAlign="left" Width="50" />
                         </telerik:GridBoundColumn>
                     </Columns>             
                 </MasterTableView>
                 <ClientSettings>
                     <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                 </ClientSettings>               
                </telerik:RadGrid>

  2. Billy8988
    Billy8988 avatar
    13 posts
    Member since:
    Jul 2008

    Posted 12 Jul 2010 Link to this post

    Okay...after spending a lot of time...it is definitely a BUG. Here is the scenario to reproduce it.
    As described in the OP, define a grid. In the NeedDataSource event, create an ArrayList of class objects which would have get method for all the data items defined in the grid. Here is the catch. These get methods return "object" instead of a specific data type. Sometimes, they could return null too (except for the anchor/hyperlink column). These "object"s are Datetime, string and null in my case. Bingo. After the grid is displayed, try to sort, you will get the error.

    I have changed the return type to string from object. It seems to have worked but I have to do my own sorting.

    BTW, I am using FileV: 2008.1.619.35

  3. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 15 Jul 2010 Link to this post

    Hello Billy,

    I tried to replicate the issue which you described, but to no avail.
    Attached to this message, you will find the code which I used for testing.

    Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.

    Regards,
    Mira
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Billy8988
    Billy8988 avatar
    13 posts
    Member since:
    Jul 2008

    Posted 15 Jul 2010 Link to this post

    Mira,

    Here is the modified version of default.aspx and .cs which should reproduce the bug.
    Thanks.

    -Bill

    ===================Default.aspx===================================
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    </head>
    <body>
        <form runat="server" id="mainForm" method="post" style="width: 1300px">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" ShowGroupPanel="True"
                Width="100%" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource">
                <MasterTableView />
                <ClientSettings AllowDragToGroup="True">
                </ClientSettings>
            </telerik:RadGrid>
        </div>
        <div>
        <telerik:RadGrid ID="ExcelGrid"  AutoGenerateColumns="false" EnableViewState="true"
                    Skin="Office2007"
                 AllowSorting="True"
                   AllowMultiRowSelection="false" runat="server" GridLines="None"
                   OnItemDataBound="ExcelGrid_ItemDataBound"
                   onneeddatasource="ExcelGrid_NeedDataSource">
                 <MasterTableView Width="100%" BorderWidth="0" TableLayout="Auto" DataKeyNames="FILE_NAME">             
                     <RowIndicatorColumn>
                         <HeaderStyle Width="20px" />
                     </RowIndicatorColumn>
                     <ExpandCollapseColumn>
                         <HeaderStyle Width="20px" />
                     </ExpandCollapseColumn>
                     <Columns>
                    <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Row#">
                        <ItemStyle HorizontalAlign="left"/>
                       <ItemTemplate>
                        <asp:Label ID="numberLabel" runat="server"/>
                       </ItemTemplate>    
                       </telerik:GridTemplateColumn>             
                         <telerik:GridTemplateColumn DataField="FILE_NAME" HeaderText="File Name"
                             SortExpression="FILE_NAME" UniqueName="FILE_NAME">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                             <ItemTemplate>                            
                                 <a href='download.aspx?type=i&docID=<%# DataBinder.Eval(Container.DataItem, "FILE_NAME").ToString() %>' target="_blank">
                                 <%# DataBinder.Eval(Container.DataItem, "FILE_NAME").ToString()%></a>
                             </ItemTemplate>
                         </telerik:GridTemplateColumn>
                         <telerik:GridBoundColumn DataField="Agreemt_Date" HeaderText="Agreement Date" DataFormatString="{0:dd/MM/yyyy}"
                             SortExpression="Agreemt_Date" UniqueName="Agreemt_Date">
                             <ItemStyle HorizontalAlign="left" Width="25" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Orig_Agmt_Type" HeaderText="Original Agreement Type"
                             SortExpression="Orig_Agmt_Type" UniqueName="Orig_Agmt_Type">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Mod_Agreemt_Type" HeaderText="Model Agreement Type"
                             SortExpression="Mod_Agreemt_Type" UniqueName="Mod_Agreemt_Type">
                             <ItemStyle HorizontalAlign="left" Width="35" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Parties" HeaderText="Parties"
                             SortExpression="Parties" UniqueName="Parties">
                             <ItemStyle HorizontalAlign="left" Width="50" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Basin" HeaderText="Basin"
                             SortExpression="Basin" UniqueName="Basin">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Municipality" HeaderText="Municipality"
                             SortExpression="Municipality" UniqueName="Municipality">
                             <ItemStyle HorizontalAlign="left" Width="75" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Sewershed_Area" HeaderText="Sewershed / Area"
                             SortExpression="Sewershed_Area" UniqueName="Sewershed_Area">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Source" HeaderText="Source"
                             SortExpression="Source" UniqueName="Source">
                             <ItemStyle HorizontalAlign="left" Width="122" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Status" HeaderText="Status"
                             SortExpression="Status" UniqueName="Status">
                             <ItemStyle HorizontalAlign="left" Width="30" />
                         </telerik:GridBoundColumn>
                         <telerik:GridBoundColumn DataField="Notes" HeaderText="Notes"
                             SortExpression="Notes" UniqueName="Notes">
                             <ItemStyle HorizontalAlign="left" Width="50" />
                         </telerik:GridBoundColumn>
                     </Columns>             
                 </MasterTableView>
                 <ClientSettings>
                     <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                 </ClientSettings>               
                </telerik:RadGrid>    
        </div>
        </form>
    </body>
    </html>
    ================End of Default.aspx=======================

    ================Default.cs========================================
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Collections;

    public partial class _Default : System.Web.UI.Page
    {
        protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            ArrayList list = new ArrayList();

            list.Add((new MyClass("string1")).Str);
            list.Add((new MyClass("string2")).Str);
            list.Add((new MyClass("string3")).Str);
            list.Add((new MyClass(null)).Str);

            RadGrid1.DataSource = list;
        }

        public class MyClass
        {
            private object str;

            public object Str
            {
                get { return str; }
                set { str = value; }
            }
            public MyClass(object o)
            {
                Str = o;
            }
        }
        protected void ExcelGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            ArrayList list = new ArrayList();
            Random randObj = new Random(0);
            for (int row = 0; row < 10; row++)
            {
                ExcelRowObj newRow = new ExcelRowObj();
                for (int col = 0; col < 11; col++)
                {

                    int num = randObj.Next();
                    switch (col)
                    {
                        case 0:
                            newRow.setValue("File " + row.ToString() + col.ToString(), col);
                            break;
                        case 1:
                            if (num % 2 != 0)
                                newRow.setValue(DateTime.Now, col);
                            break;
                        default:
                            if (num % 2 == 0)
                                newRow.setValue("string " + row.ToString() + col.ToString(), col);
                            break;
                    }
                }
                list.Add(newRow);
            }
            ExcelGrid.DataSource = list;
        }
        protected void ExcelGrid_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                Label lbl = e.Item.FindControl("numberLabel") as Label;
                lbl.Text = (e.Item.ItemIndex + 1).ToString();
            }
        }

        public class ExcelRowObj
        {
            object[] values;

            public ExcelRowObj()
            {
                values = new object[11];
                for (int i = 0; i < 11; i++)
                {
                    values[i] = null;
                }
            }
            public void setValue(object val, int index)
            {
                values[index] = val;
            }
            public object getValue(int index)
            {
                return values[index];
            }
            public object FILE_NAME
            {
                get { return getValue(0); }
            }
            public object Agreemt_Date
            {
                get { return getValue(1); }
            }
            public object Orig_Agmt_Type
            {
                get { return getValue(2); }
            }
            public object Mod_Agreemt_Type
            {
                get { return getValue(3); }
            }
            public object Parties
            {
                get { return getValue(4); }
            }
            public object Basin
            {
                get { return getValue(5); }
            }
            public object Municipality
            {
                get { return getValue(6); }
            }
            public object Sewershed_Area
            {
                get { return getValue(7); }
            }
            public object Source
            {
                get { return getValue(8); }
            }
            public object Status
            {
                get { return getValue(9); }
            }
            public object Notes
            {
                get { return getValue(10); }
            }
        }

    }
    ================End of Default.cs=========================
  5. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 20 Jul 2010 Link to this post

    Hello Billy,

    I have examined your code and I suggest that you cast the data before populating the grid.
    For example:
    public string Orig_Agmt_Type
    {
        get { return (getValue(2) != null ? getValue(2).ToString() : ""); }
    }

    I hope this helps.

    Greetings,
    Mira
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Billy8988
    Billy8988 avatar
    13 posts
    Member since:
    Jul 2008

    Posted 21 Jul 2010 Link to this post

    Well...it doesn't make sense to change everything into a string object, is it?
    If I want to sort a Datetime column, it will sort it as string.

    -Bill
  7. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 23 Jul 2010 Link to this post

    Hello Billy,

    The RadGrid can be bound only to the property types listed in this help topic.

    To implement the desired functionality, you should cast the data before populating the grid.

    Sincerely yours,
    Mira
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Billy8988
    Billy8988 avatar
    13 posts
    Member since:
    Jul 2008

    Posted 23 Jul 2010 Link to this post

    Mira,

    Is it crashing because DateTime column contains nulls as it is not a nullable object?
    How do you handle a select query that may have a nullable DateTime column?

    casting option is not kosher for the reasons I described in my earlier post.

    -Bill
     
  9. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2289 posts

    Posted 29 Jul 2010 Link to this post

    Hello Billy,

    Indeed my colleague Mira is correct. RadGrid has list of bindable type(as  listed in her last post) and "object" isn't on of them. RadGrid will manage the binding, it will result in <object>.ToString(), but any other operations will not function properly.

    Regards,
    Nikolay
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. scalpello
    scalpello avatar
    1 posts
    Member since:
    May 2011

    Posted 19 Oct 2011 Link to this post

    The datasource of my rad grid is a datatable, and the column of the grid is the same in the datatable, but when i order a column I have the error "System.IndexOutOfRangeException: Cannot find column".
  11. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 24 Oct 2011 Link to this post

    Hello Scalpello,

    How is the grid data-bound?
    Please make sure that you use either simple, or advanced data-binding and do not mix them.

    I hope this helps.

    Kind regards,
    Mira
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top