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

Is their a way to get postback on a GridView column. I need this for sorting a column

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 11 May 2014, 05:14 PM
Hello, I a web page with a telerik gridview control. For one of the columns, I would like for the user to be able to sort on the column. I can do the sorting in my C# code behind file. However, is their a way to get postback when someone presses the gridview header for the column? You see if I can get postback that way, then I can sort the data and rebid the grid with the sorted data.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 May 2014, 12:40 PM
Hi Raymond,

RadGrid has a property  AllowSorting="true" which sorts the column on click of the column header. In case you want to have a postback, you can have an AjaxRequest set on client-side columnclick event and handle the sort manually. Please take a look at the following code snippet.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server" >
    <ClientSettings>
        <ClientEvents OnColumnClick="OnColumnClick" />
    </ClientSettings>
</telerik:RadGrid>

JS:
<script type="text/javascript">
    function OnColumnClick(sender, args) {
        var ajax = $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest();
    }
</script>

C#:
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
    SortGrid();
}
protected void SortGrid()
{
   // code to Sort the gird
}

Thanks,
Shinu
Tags
General Discussions
Asked by
Raymond
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or