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

Displaying Sort Icon by default.

2 Answers 206 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Puttu
Top achievements
Rank 1
Puttu asked on 09 Feb 2009, 01:09 PM

I want to show Sort Icon on a column by default when the RADGrid loads for the firsttime. Currently, the Sort Icon appears only after I click it. Is there any property of RADGrid that shows Sort Icon by default?

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Feb 2009, 04:02 AM
Hi,

You can achieve this by setting the SortExpression for the Grid in the PreRender event. Set the FieldName for the SortExpression with  the DataField of the desired column.

CS:
  protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        GridSortExpression SortExp = new GridSortExpression(); 
        SortExp.FieldName = "ProductName"
        SortExp.SortOrder = GridSortOrder.Ascending; 
        RadGrid1.MasterTableView.SortExpressions.Add(SortExp); 
        RadGrid1.MasterTableView.Rebind(); 
    } 


Shinu.
0
CHETAN JAITLY
Top achievements
Rank 1
answered on 16 Feb 2009, 10:58 AM
Hi,
As per this code for default sort icon, It create a problem when we add another code for header click event of sorting.
as for ex I have written in radgrid_prerender event I have written the code for sorting on header click event. Now if I am paste this sort icon default code in pre render it always sort by that default column. If I clicked on any other column then also it sort by default column.

Protected Sub RadGridContacts_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGridContacts.PreRender                
       GridSortExpression SortExp = new GridSortExpression(); 
        SortExp.FieldName = "Email"; 
        SortExp.SortOrder = GridSortOrder.Ascending; 
        RadGridContacts.MasterTableView.SortExpressions.Add(SortExp); 
        RadGridContacts.MasterTableView.Rebind(); 
        Dim iCounter As Integer = 0
        For Each col As GridColumn In RadGridContacts.MasterTableView.RenderColumns
            For Each header As GridHeaderItem In RadGridContacts.MasterTableView.GetItems(GridItemType.Header)
                If iCounter > 3 Then
                    header(col.UniqueName).Attributes.Add("OnClick", "return SortColumn('" & col.UniqueName & "');")
               End If
               iCounter = iCounter + 1
           Next
       Next
  End sub

Thanks,
Jalps

 

Tags
Grid
Asked by
Puttu
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
CHETAN JAITLY
Top achievements
Rank 1
Share this question
or