Solved

Sort Gridview Inside Update Panel

Posted on 2014-01-06
3
1,044 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
Comment Utility
0
 
LVL 16

Accepted Solution

by:
Kamal Khaleefa earned 500 total points
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now