Solved

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

Posted on 2006-11-08
9
420 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

16 Experts available now in Live!

Get 1:1 Help Now