?
Solved

Sort Gridview Inside Update Panel

Posted on 2014-01-06
3
Medium Priority
?
1,190 Views
Last Modified: 2014-01-06
Hi,

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
0
Comment
Question by:vstack
3 Comments
 
LVL 8

Expert Comment

by:5teveo
ID: 39760538
0
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 2000 total points
ID: 39761204
hi
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"  
                                                                      Width="100%"
                                                                    AllowPaging="true" PageSize="10">
                                                              
                                                                    
                                                                    <Columns>

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

  </Columns>
  </asp:GridView>

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

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

 GridView1.DataSource = dv
            GridView1.DataBind()
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
        ChangeSortDir()

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

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

    End Sub

Open in new window

0
 

Author Closing Comment

by:vstack
ID: 39761362
Thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

864 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