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

RadGrid Sort Programatically

3 Answers 685 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jagat
Top achievements
Rank 1
Jagat asked on 05 Nov 2012, 07:44 PM
Hi,

How do I get the columnName/UniqueName of the field that has been clicked in order to sort the grid by that column?

Thank you !!

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Nov 2012, 03:49 AM
Hi,

I guess you want to get the column UniqueName when the column is sorted. Please take a look into the following code snippet.

C#:
protected void RadGrid1_SortCommand(object sender, GridSortCommandEventArgs e)
{
    string datafield = e.SortExpression;  //you will get the column Datafield
    foreach(GridColumn col in RadGrid1.MasterTableView.RenderColumns)
    {
        if (col is GridBoundColumn && (col as GridBoundColumn).DataField == e.SortExpression)
        {
            string uniquename = col.UniqueName;  //you will get the column uniqueName(of bound column for example)
        }
   
    }
}

Thanks,
Shinu.
0
Ryan
Top achievements
Rank 1
answered on 14 Nov 2012, 12:13 PM
Hi Shinu,


Could you give me the complete code for programmatic sorting. Actually i want to all functionality in code behind. I would like tosort a column by ascending order on page load itself. Please provide a solution soon. Its urgent.


Thanks,
RT.
0
Shinu
Top achievements
Rank 2
answered on 14 Nov 2012, 12:19 PM
Hi,

You can set the sort expression programmatically as shown below.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
 GridSortExpression expression = new GridSortExpression();
 expression.FieldName = "UniqueName";
 expression.SortOrder = GridSortOrder.Ascending;
 RadGrid1.MasterTableView.SortExpressions.AddSortExpression(expression);
 RadGrid1.MasterTableView.Rebind();
}

Thanks,
Shinu.
Tags
Grid
Asked by
Jagat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ryan
Top achievements
Rank 1
Share this question
or