Solved

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

Posted on 2006-11-08
9
450 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
Technology Partners: 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!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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