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

Sorting is not working in RadGrid

1 Answer 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farrukh
Top achievements
Rank 1
Farrukh asked on 04 Jan 2012, 08:12 AM
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>



1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Jan 2012, 09:19 AM
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
Tags
Grid
Asked by
Farrukh
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or