Solved

Manually sorting and paging a GridView in ASP.NET(VB/VS2k5)

Posted on 2006-11-08
9
405 Views
Last Modified: 2012-05-05
In 2003 i would have a DataGrid tag like this

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnSortCommand="SortCommand_OnClick" OnPageIndexChanged="dgTitles_Paging">

which called this

    Sub dgTitles_Paging(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
      GridView1.CurrentPageIndex = e.NewPageIndex
       BindData()
    End Sub
    Sub SortCommand_OnClick(ByVal Source As Object, ByVal E As DataGridSortCommandEventArgs)
        Label1.Text = "SELECT NCR_ID, ORDER_QTY, REJECTED_DATE from tblMain " & E.SortExpression
        BindData()
    End Sub

This obviously doesn't work in 2005. So how do I manually set up sorting/paging for a GridView in 05?   TIA
0
Comment
Question by:mwmiller78
9 Comments
 
LVL 3

Expert Comment

by:Bluford
ID: 17902483
I think you can still do the same thing with a DataGrid in 2005 as you did in 2003, but in the code above you are trying to use GridView.  Change it back to DataGrid and it should work fine.
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17903236
0
 

Author Comment

by:mwmiller78
ID: 17906652
Blu,

I can't just change it back to DataGrid because it's not a datagrid, its a GridView. Is there a datagrid control in 2005?
0
 

Author Comment

by:mwmiller78
ID: 17909473
I got it. Here it is...

html...
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="GridView_PageIndexChanging" OnSorting="SortCommand_OnClick">

and the code behind...
    Protected Sub GridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
        BindData()
    End Sub
    Protected Sub SortCommand_OnClick(ByVal Source As Object, ByVal E As GridViewSortEventArgs)
        Label1.Text = "SELECT NCR_ID, ORDER_QTY, REJECTED_DATE from tblMain ORDER BY " & E.SortExpression
        BindData()
    End Sub


thanks guys

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 3

Expert Comment

by:Bluford
ID: 17912987
Yep that would work.  FYI, the DataGrid control still works in ASP.NET 2.0 and VS 2005.  There is not a DataGrid control listed in the controls toolbar, but you can still use DataGrid if you manually type it in.  There is no particular need to switch everything over to using GridViews, unless you need the enhanced functionality it provides.
0
 

Author Comment

by:mwmiller78
ID: 17914226
I actually tried that before and it wasn't working for me. I just assumed that VS just changed from grid to view. Is there a namespace/reference i need to address to use the grid?
0
 
LVL 3

Expert Comment

by:Bluford
ID: 17918634
There should not be any special references required.  On my system, I can open up a project, go into source view of an .aspx page, and insert the following code:

<asp:DataGrid runat="server" ID="myDataGrid"></asp:DataGrid>

Then I am able to use all the Visual Studio 2005 tools to modify its properties, in both code and design view.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17964655
PAQd, 500 points refunded.

DarthMod
CS Moderator
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

9 Experts available now in Live!

Get 1:1 Help Now