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

2 posts, 0 answers
  1. Raymond
    Raymond avatar
    1 posts
    Member since:
    May 2014

    Posted 11 May 2014 Link to this post

    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.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 May 2014 in reply to Raymond Link to this post

    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
Back to Top