I am trying use the sorting properties in the radgrid, and I am wondering if there is a way to sort the data bound to the grid without hitting the database again. My problem is when I do not hit the database and attempt to sort, my data in the grid disappears.
My radgrid is set up to look like this:
My code behind methods for sorting and loading the radgrid are shown below:
The LoadData method is used to get the results from the database and returns a data set which I bind to the radgrid.
The Sort method I tried using from the demo, I found here:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultcs.aspx
From this I would like to be able to sort all of my columns, except for the effective column, in ascending or descending order depending on what the user selects. I was also curious if you could offer up any assitance as to how to go about sorting my Item Template column, if that is possible. Since, my CustomerID is bound to the column and I just use code to display the customer's status, I was not sure if this was possible to sort by the actual status name.
Any assistance would be appreciated. Thanks.
Joe
My radgrid is set up to look like this:
<
radG:RadGrid
ID
=
"CustomerGrid"
runat
=
"server"
AutoGenerateColumns
=
"false"
Width
=
"100%"
EnableAJAX
=
"True"
OnPageIndexChanged
=
"SearchResults_PageIndexChanged"
Skin
=
"Office2007"
AllowFilteringByColumn
=
"False"
AllowPaging
=
"True"
PageSize
=
"35"
ShowStatusBar
=
"True"
ShowFooter
=
"False"
ShowGroupPanel
=
"False"
GridLines
=
"None"
CellPadding
=
"1"
AllowSorting
=
"True"
OnSortCommand
=
"RadGrid1_SortCommand"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
EditMode
=
"InPlace"
ShowFooter
=
"True"
Width
=
"99%"
TableLayout
=
"Auto"
AllowMultiColumnSorting
=
"true"
AllowNaturalSort
=
"true"
>
<
Columns
>
<
radG:GridBoundColumn
DataField
=
"CustomerID"
HeaderText
=
"Customer Number"
SortExpression
=
"CustomerID"
UniqueName
=
"CustomerID"
>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
DataField
=
"CustomerName"
HeaderText
=
"Customer Name"
SortExpression
=
"CustomerName"
UniqueName
=
"CustomerName"
>
</
radG:GridBoundColumn
>
<
radG:GridTemplateColumn
HeaderText
=
"Status"
HeaderStyle-Width
=
"160px"
ItemStyle-Width
=
"160px"
>
<
ItemTemplate
>
<%# GetStatus(Eval("CustomerID")) %>
</
ItemTemplate
>
</
radG:GridTemplateColumn
>
<
radG:GridBoundColumn
DataField
=
"Effective"
HeaderText
=
"Effective"
>
</
radG:GridBoundColumn
>
</
Columns
>
<
ExpandCollapseColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"19px"
/>
</
ExpandCollapseColumn
>
<
RowIndicatorColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"20px"
/>
</
RowIndicatorColumn
>
</
MasterTableView
>
<
ClientSettings
ReorderColumnsOnClient
=
"True"
AllowDragToGroup
=
"True"
AllowColumnsReorder
=
"True"
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
></
Scrolling
>
</
ClientSettings
>
</
radG:RadGrid
>
My code behind methods for sorting and loading the radgrid are shown below:
protected
void
SearchResults_PageIndexChanged(
object
source, Telerik.WebControls.GridPageChangedEventArgs e)
{
LoadData();
}
protected
void
RadGrid1_SortCommand(
object
source, Telerik.WebControls.GridSortCommandEventArgs e)
{
if
(!e.Item.OwnerTableView.SortExpressions.ContainsExpression(e.SortExpression))
{
GridSortExpression sortExpr =
new
GridSortExpression();
sortExpr.FieldName = e.SortExpression;
sortExpr.SortOrder = GridSortOrder.Ascending;
e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
}
}
The LoadData method is used to get the results from the database and returns a data set which I bind to the radgrid.
The Sort method I tried using from the demo, I found here:
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/sorting/defaultcs.aspx
From this I would like to be able to sort all of my columns, except for the effective column, in ascending or descending order depending on what the user selects. I was also curious if you could offer up any assitance as to how to go about sorting my Item Template column, if that is possible. Since, my CustomerID is bound to the column and I just use code to display the customer's status, I was not sure if this was possible to sort by the actual status name.
Any assistance would be appreciated. Thanks.
Joe