Sorting is not working in RadGrid

2 posts, 0 answers
  1. Farrukh
    Farrukh avatar
    12 posts
    Member since:
    May 2009

    Posted 04 Jan 2012 Link to this post

    Hi ,

     

     

    I am using property class object inside to another property class for reusability as shown below. My problem is that when I click sort on EMP_ID column then error will occur as shown below. but it will working on all the other company direct fields like company_ID, company_Name but for others inherited columns its gives error check the given below code and advise me how to fixed this error thanks.


    If I EnableLinqExpressions="false" then its give me error like this

    Cannot find column EMP_ID.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.IndexOutOfRangeException: Cannot find column EMP_ID.



    If I EnableLinqExpressions="true" then its give me error like this

     

     

     


    No property or field 'EMP_ID' exists in type 'Company'

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Telerik.Web.UI.ParseException: No property or field 'EMP_ID' exists in type Company'

    If I ="true" then its give me error like this



    public class Employee
      
    {
     public int Emp_ID { get; set; }
      
    public string Emp_Name { get; set; }
      
    public string Email { get; set; }
      
    public bool? IsActive { get; set; }
      
    public bool? Flag { get; set; }
      
    public string Password { get; set; }
      
    public int Role_ID { get; set; }
      }
      
    public class Company
      {
    public int Company_ID { get; set; }
      
    public string Company_Name { get; set; }
      
    public string Phone_No { get; set; }
      
    private Employee _modelEmployee;
      
    public Employee ModelEmployee
      
    {
    get
    {
    if (_modelEmployee == null)
    _modelEmployee = new Employee();
    return _modelEmployee;
    }
    set
    {
    _modelEmployee = value;
    }
    }
    }

    <telerik:RadGrid ID="grdSearch" runat="server" AllowSorting="True" AllowPaging="True"
                       EnableLinqExpressions="false" AllowCustomPaging="True" GridLines="None" Skin="Vista"
                       ShowGroupPanel="True">
                       <MasterTableView AutoGenerateColumns="False" DataKeyNames="Company_ID">
                           <RowIndicatorColumn>
                               <HeaderStyle Width="20px"></HeaderStyle>
                           </RowIndicatorColumn>
                           <ExpandCollapseColumn>
                               <HeaderStyle Width="20px"></HeaderStyle>
                           </ExpandCollapseColumn>
                           <Columns>
                               <telerik:GridBoundColumn DataField="Company_ID" DataType="System.Int32" HeaderText="Company_ID"
                                   SortExpression="Company_ID" UniqueName="Company_ID">
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="ModelEmployee.Emp_Name" DataType="System.String"
                                   HeaderText="Emp_Name" SortExpression="Emp_Name" UniqueName="Emp_Name">
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="ModelEmployee.Emp_ID" DataType="System.Int32"
                                   HeaderText="Emp_ID" SortExpression="Emp_ID" UniqueName="Emp_ID">
                               </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn DataField="ModelEmployee.Role_ID" DataType="System.Int32"
                                   HeaderText="Role_ID" SortExpression="Role_ID" UniqueName="Role_ID">
                               </telerik:GridBoundColumn>                           
                               <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="column1" HeaderText="Edit">
                               </telerik:GridButtonColumn>
                               <telerik:GridButtonColumn CommandName="View" Text="View" UniqueName="column" HeaderText="View">
                               </telerik:GridButtonColumn>
                           </Columns>
                       </MasterTableView>
                       <ClientSettings AllowDragToGroup="true" />
                   </telerik:RadGrid>



  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 04 Jan 2012 Link to this post

    Hello,

    try with below code.

    <telerik:GridBoundColumn DataField="ModelEmployee.Emp_ID" DataType="System.Int32"
                                   HeaderText="Emp_ID"  UniqueName="Emp_ID">
    or
     
    <telerik:GridBoundColumn DataField="ModelEmployee.Emp_ID" DataType="System.Int32"
                                   HeaderText="Emp_ID" SortExpression="ModelEmployee.Emp_ID" UniqueName="Emp_ID">


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top