Sort Gridview Inside Update Panel

Posted on 2014-01-06
Last Modified: 2014-01-06

I understand sorting a gridview inside an update panel is not compatible (see

BUT is there a workaround?

Thank you
Question by:vstack
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 39760538
LVL 16

Accepted Solution

Kamal Khaleefa earned 500 total points
ID: 39761204
it is very easy to sort a grid view inside updatapanel

here is my code

In ASPX Page
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"  
                                                                    AllowPaging="true" PageSize="10">

 <asp:TemplateField  >
                                                                                            <asp:LinkButton ID="lnkCameraPermitID"  
                                                                                                Text="Pass ID" runat="server" OnClick="Sort"></asp:LinkButton>
                                                                                <asp:LinkButton ID="lnk_CameraPermitID"  runat="server"
                                                                                    CommandName="Select" CommandArgument='<%#DataBinder.eval(container,"Dataitem.CameraPermitID") %>'
                                                                                    Text='<%#DataBinder.eval(container,"Dataitem.CameraPermitID") %>'></asp:LinkButton>


Open in new window

now when you clik on the header sort will happen.
note that i name the header ID like This "lnk"+Data Base Column name
ID="lnkCameraPermitID"  so CameraPermitID is my database cloumn that we will do the sort according to it

now in your code behind do this
 Sub LoadCameraPermits()
   Dim dt As New DataTable

  If Not ViewState("SortColumn") Is Nothing Then
                dv.Sort = (ViewState("SortColumn").ToString() + ViewState("SortDir").ToString()).ToString()
            End If

 GridView1.DataSource = dv
end sub 

 Sub Sort(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim LinkButton1 As LinkButton = CType(sender, LinkButton)
        ViewState("SortColumn") = LinkButton1.ID.Substring(3).ToString

        '  If ViewState("Type") Is Nothing Then ViewState("Type") = 1
    End Sub

    Protected Sub ChangeSortDir()
        If ViewState("SortDir") Is Nothing Then
            ViewState("SortDir") = " ASC"
            If ViewState("SortDir").ToString() = " ASC" Then
                ViewState("SortDir") = " DESC"
                ViewState("SortDir") = " ASC"
            End If
        End If

    End Sub

Open in new window


Author Closing Comment

ID: 39761362

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
TimeZone, day light savings, Sql server, 6 39
Finding the IIS version 5 38
ASP.NET Content Page 3 52
Asp.Net Session Question 2 36
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question