Solved

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

Posted on 2006-11-08
9
455 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:Mike Miller
[X]
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
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:Mike Miller
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:Mike Miller
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
 
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:Mike Miller
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

Industry Leaders: 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

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 .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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