Sort Gridview Inside Update Panel

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

I understand sorting a gridview inside an update panel is not compatible (see http://msdn.microsoft.com/en-us/library/bb386454.aspx)

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 2000 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

Technology Partners: 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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

765 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