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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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