ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
ToltingColtAcres
asked on 07 Jan 2011, 09:56 PM
I need to be able to sort a RadGrid GridDropDownColumn by the ListTextField and not the ListValueField.
Can someone provide an example on how I can accomplish this?
Can someone provide an example on how I can accomplish this?
5 Answers, 1 is accepted
0
Mike Nogen
Top achievements
Rank 1
answered on 07 Jan 2011, 10:43 PM
Hello!
Have you tried using the property SortExpression in the GridDropDownColumn
Have you tried using the property SortExpression in the GridDropDownColumn
SortExpression
=
"CompanyName" instead of the ID/value
/M
0
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
answered on 07 Jan 2011, 10:49 PM
Tried that. I get an error.
The datasource select is "SELECT Name, Employee_GUID FROM Employees ORDER BY Name"
The griddropdowncolumn definition is:
<telerik:GridDropDownColumn DataField="Employee_GUID"
DataSourceID="sqlDataSource_Employees" HeaderText="Employee"
ListTextField="Name"
ListValueField="Employee_GUID" UniqueName="Employee_GUID">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</telerik:GridDropDownColumn>
if I add a SortExpression="Name" to the definition, when I attempt to sort, I get:
Server Error in '/VehicleTracking' Application.
Exception Details: System.IndexOutOfRangeException: Cannot find column Name.
Source Error:
Stack Trace:
The datasource select is "SELECT Name, Employee_GUID FROM Employees ORDER BY Name"
The griddropdowncolumn definition is:
<telerik:GridDropDownColumn DataField="Employee_GUID"
DataSourceID="sqlDataSource_Employees" HeaderText="Employee"
ListTextField="Name"
ListValueField="Employee_GUID" UniqueName="Employee_GUID">
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</telerik:GridDropDownColumn>
if I add a SortExpression="Name" to the definition, when I attempt to sort, I get:
Server Error in '/VehicleTracking' Application.
Cannot find column Name.
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 Name.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
|
0
Mike Nogen
Top achievements
Rank 1
answered on 08 Jan 2011, 01:47 AM
Sorry,my fault. It wasn´t that easy. Telerik stated on ther help pages that it´s NOT supported in the current version of the Grid.
http://www.telerik.com/help/aspnet/grid/grdfilteringbylisttextfieldforgriddropdowncolumn.html
Depening on you current solution and datasource you can try hooking up an SortCommand (I haven´t tried it) .
http://www.telerik.com/help/aspnet/grid/grdapplycustomsortcriteria.html
http://www.telerik.com/help/aspnet/grid/grdfilteringbylisttextfieldforgriddropdowncolumn.html
Depening on you current solution and datasource you can try hooking up an SortCommand (I haven´t tried it) .
http://www.telerik.com/help/aspnet/grid/grdapplycustomsortcriteria.html
protected
void
RadGrid1_SortCommand(
object
source, GridSortCommandEventArgs e)
{
if
(e.CommandArgument ==
"Employee_GUID"
)
{
switch
(e.OldSortOrder)
{
case
GridSortOrder.None:
e.Item.OwnerTableView.DataSource =
GetDataTable(
"SELECT FirstName, LastName FROM Employees ORDER BY LEN(FirstName) ASC"
);
e.Item.OwnerTableView.Rebind();
break
;
case
GridSortOrder.Ascending:
e.Item.OwnerTableView.DataSource =
GetDataTable(
"SELECT FirstName, LastName FROM Employees ORDER BY LEN(FirstName) DESC"
);
e.Item.OwnerTableView.Rebind();
break
;
case
GridSortOrder.Descending:
e.Item.OwnerTableView.DataSource =
GetDataTable(
"SELECT FirstName, LastName FROM Employees"
);
e.Item.OwnerTableView.Rebind();
break
;
}
}
}
0
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
answered on 08 Jan 2011, 02:25 AM
Yea, i saw that, was hoping it didn't apply to sorts (since it mentioned filtering).
I tried intercepting the sortcommand (I have an sqldatasource for the source table) but it didn't help.
Still sorts by the GUID.
This seems to be a major limitation, I can't imagine why Telerik would sort based on the value and not the text, since what people see is the text and they don't even care what the underlying value (foreign key) is. Seems downright silly to me that you can't do this.
I tried intercepting the sortcommand (I have an sqldatasource for the source table) but it didn't help.
protected void RadGrid_Vehicles_SortCommand(object sender, GridSortCommandEventArgs e)
{
if (e.CommandArgument == "Employee_GUID")
{
switch (e.NewSortOrder)
{
case GridSortOrder.None:
case GridSortOrder.Ascending:
SqlDataSource_Employees.SelectCommand = "SELECT Name, Employee_GUID FROM Employees ORDER BY Name ASC";
SqlDataSource_Employees.Select(DataSourceSelectArguments.Empty);
e.Item.OwnerTableView.Rebind();
break;
case GridSortOrder.Descending:
SqlDataSource_Employees.SelectCommand = "SELECT Name, Employee_GUID FROM Employees ORDER BY Name DESC";
SqlDataSource_Employees.Select(DataSourceSelectArguments.Empty);
e.Item.OwnerTableView.Rebind();
break;
}
}
}
Still sorts by the GUID.
This seems to be a major limitation, I can't imagine why Telerik would sort based on the value and not the text, since what people see is the text and they don't even care what the underlying value (foreign key) is. Seems downright silly to me that you can't do this.
0
Hi Michael,
That's because the text field in a GriDropDownColumn is not contained in RadGrid's data source. The text field specifies records from another database table related to RadGrid's table by a foreign key specified by the DataField and ListValueField properties. RadGrid's own data table does not contain the DataTextField. You cannot sort of filter by data that is not in the data source of the grid. If you make a JOIN and add the data text field to RadGrid's own data source, then you can specify the field name in the SortExpression property of the column.
Veli
the Telerik team
That's because the text field in a GriDropDownColumn is not contained in RadGrid's data source. The text field specifies records from another database table related to RadGrid's table by a foreign key specified by the DataField and ListValueField properties. RadGrid's own data table does not contain the DataTextField. You cannot sort of filter by data that is not in the data source of the grid. If you make a JOIN and add the data text field to RadGrid's own data source, then you can specify the field name in the SortExpression property of the column.
Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.