CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 1/24/2006 6:55:57 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 185 Views: 237 Favorited: 0 Favorite
186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|
venkat_se
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource2/24/2006 7:18:28 AM

0

Thanks ...This is very useful content
Thanx & Regards,
Venkat Addanki
popolearncode
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource2/24/2006 6:10:53 PM

0

Hi Ryan,
This post is really great and i think would be better if this includes custom paging navigator which i highly appreciated if you could provide ones. For example
First | Previous | Showing 1 -10 of products | Next | Last.

Thank you

vdahiya
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/16/2006 6:46:50 PM

0

Hello Ryan,

I am using a wizard control and in that control I have a gridView which I am binding to an arraylist. Initially it threw an error when i enabled paging, so I implemented the PageIndexChanging event handler and now there is no error. But when I click on the number to goto some other page in that grid it(grid) just disappears. Do you have any idea why its happening?
I would really appreciate the help.

Thanks..
VD
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/16/2006 7:05:48 PM

0

vdahiya wrote:
Initially it threw an error when i enabled paging, so I implemented the PageIndexChanging event handler and now there is no error. But when I click on the number to goto some other page in that grid it(grid) just disappears.

Instead of an ArrayList, I would use a generic List collection as the data source. Did you follow what I did in the example above for paging?

HTH,
Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
vdahiya
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/17/2006 6:23:01 PM

0

Ryan,

Here is my code:

protected void gvModels_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvModels.DataSource = myList;  //arraylist which I am binding to  (1)
        gvModels.DataBind();                 // (2)

        gvModels.PageIndex = e.NewPageIndex;
        gvTModels.DataBind();
    }
I put line markerd (1) and (2) just now to see if it makes any difference.

Thanks.
VD


StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/17/2006 6:31:03 PM

0

Does myList contain any items when you set it as the data source?


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
vdahiya
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/17/2006 9:23:43 PM

0

Yeah It does contain the data.

Finally I got what I was missing. I was not caching the contents of myList for the postbacks. So after it does a postback, the contents of the list are wiped off which results in my gridView getting disappear...Its working fine now.
Thanks a lot for your help.

~VD

mintesa
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/22/2006 6:04:02 PM

0

hi ryan

would like to thank you for this post. it helped me a lot for my BS project which i am doing in asp.net 2.0, and none of my books said anything about it.

im so happy i found this post Big Smile [:D] thanx!


smile!
mintesa
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/24/2006 2:14:46 PM

0

hi ryan

is there some way to make the PageIndexChaning and the OnSorting work together, so that you can sort a column first, and then go through the pages, without the sort to change?

 

thanx


smile!
assemblage
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource3/28/2006 5:58:31 PM

0

I came across this trying to do an admin panel for membership and profiles.  I had users first and last name stored in the profiles.  Since the default sql profile provider doesn't have a method that I'm aware of to retrive those values and bind to a gridview, I load the username, and "lastname, firstname" field into a datatable and bind that to a gridview.  This gridview control needs to act like all the other gridviews with sorting and paging, which is where Ryan's code has been helpful.  But the sorting doesn't hold when pages are changed.  I made some mods and think I added that functionality it.

Source: http://www.learnasp.com/freebook/learn/cs_GridViewSortingNoDataSourceControl.aspx

1) I put the PopulatePublishersGridView(); in the Page_Init event method.  I believe this calls the method once instead of everytime the page loads.  The gridview control stores the information on subsequent page loads in the viewstate.

2)I would think that after the GridView control's DataSource is set to a DataTable it would be saved in the ViewState.  So if you changed the DataTable in the GridView's DataSource, those changes would be reflected in the GridView and saved in the ViewState.

Continuing with my thought...that means if you sort the table, thus changing the table, then rebind it, thus saving it to the GridView, then those changes would also be reflected in the ViewState so when you change pages of the GridView control, the info would still be sorted.

It doesn't seem to work that way.  Maybe I'm missing something more fundamental in how these things work.  But I worked around this by saving the sort field in the ViewState after a sort is done and then again sorting in the PageIndexChanged event method.  This means when you change page, it retrieves the saved sort field and direction and sorts and then changes page.

3) Just like the GridViewSortDirection, I saved a GridViewSortExpression.

        private String GridViewSortExpression
    {
        get { return ViewState["SortExp"] as String ?? ""; }
        set { ViewState["SortExp"] = value; }
    }

4)In the "gridViewPublishers_Sorting" event method, I added:

     GridViewSortExpression = e.SortExpression;

5)To keep from having redundant code in the Sorting and PageIndexChanging event methods, I created a function for the sorting:

   protected DataView SortTable (DataTable dt)
    {
        DataView dv=new DataView();
        if (dt != null)
        {
            dv = new DataView(dt);
            if(GridViewSortExpression != "")
            {
                dv.Sort = GridViewSortExpression + " " +  
                GridViewSortDirection;
             }
        }
        return dv;
    }

6) I then added:

    gridView.DataSource = SortTable(gridView.DataSource as  DataTable);

to the PageIndexChanging before the page is changed and replaced code in the Sorting event methods.

7) I haven't fully tested, but it seems to work.

 
Jangyoung
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 3:34:37 PM

0

Hi.

When I tried to sort, it does not work.

The error message is that

 "Unable to cast object of type 'System.Data.DataView' to type 'System.Data.DataTable'."'

Dim

m_DataTable As DataTable = gridViewPublishers.DataSource

 

I copied your VB source and pasted onto my page exactly, and I am having the error above. 

Can you help me please? I've tried to solve paging and sorting with Gridview for two days in a row.

Thanks.

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 3:47:23 PM

0

Of what data type is the data source of your GridView? From that error, it appears its a DataView, while the one in my example is a DataTable.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
Jangyoung
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 4:32:37 PM

0

I just found that

Data type is System.Data.DataView, not System.Data.DataTable.

How can I change  data type from Data.DataView to System.Data.DataTable.

I think I bounded data using System.Data.DataTable like this "gridViewPublishers.DataSource = m_DataTable_Publishers"

As I told you, I exactly copied your VB source and pasted onto my TEST.aspx page.

I'm attatching my Test.aspx file.... Thank a lot.

---------------------------------------------------------------------------------------

Partial

Class Test

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

PopulatePublishersGridView()

End Sub

Private Sub PopulatePublishersGridView()

Dim Con As New OleDbConnection()

Con.ConnectionString = ConfigurationManager.ConnectionStrings(

"BILL").ConnectionString

Dim m_Sql_Query As String

m_Sql_Query =

"SELECT * FROM [UsabilityTests] ORDER BY testdate DESC"

Dim m_Access_Command As New OleDbCommand(m_Sql_Query, Con)

Dim m_DataAdapter_Publishers As New OleDbDataAdapter(m_Access_Command)

Dim m_DataTable_Publishers As New DataTable("Publishers")

m_DataAdapter_Publishers.Fill(m_DataTable_Publishers)

Dim m_DataTable_RowCount As Integer

m_DataTable_RowCount = m_DataTable_Publishers.Rows.Count

If m_DataTable_RowCount > 0 Then

gridViewPublishers.DataSource = m_DataTable_Publishers

gridViewPublishers.DataBind()

End If

End Sub

Private Property GridViewSortDirection() As String

Get

Return IIf(ViewState("SortDirection") = Nothing, "DESC", ViewState("SortDirection"))

End Get

Set(ByVal value As String)

ViewState(

"SortDirection") = value

End Set

End Property

Private Function GetSortDirection() As String

Select Case GridViewSortDirection

Case "ASC"

GridViewSortDirection =

"DESC"

Case "DESC"

GridViewSortDirection =

"ASC"

End Select

Return GridViewSortDirection

End Function

Protected Sub gridViewPublishers_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs) Handles gridViewPublishers.PageIndexChanging

gridViewPublishers.PageIndex = e.NewPageIndex

gridViewPublishers.DataBind()

End Sub

Protected Sub gridViewPublishers_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridViewPublishers.Sorting

Label1.Text = gridViewPublishers.DataSource.GetType().ToString()

Dim m_DataTable As DataTable = gridViewPublishers.DataSource

If Not m_DataTable Is Nothing Then

Dim m_PageIndex As Integer = gridViewPublishers.PageIndex

Dim m_SortDirection As String = GetSortDirection()

Dim m_DataView As New DataView(m_DataTable)

m_DataView.Sort = e.SortExpression &

" " & m_SortDirection

gridViewPublishers.DataSource = m_DataView

gridViewPublishers.DataBind()

gridViewPublishers.PageIndex = m_PageIndex

End If

End Sub

End

Class
Jangyoung
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 5:04:18 PM

0

Hello, again.

I found something really strange.

if I just test the example below

Protected Sub gridViewPublishers_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridViewPublishers.Sorting

Label1.Text = gridViewPublishers.DataSource.GetType().ToString()

End Sub

gridViewPublishers.DataSource.GetType().ToStirng() =  System.Data.DataTable

However, If I add  the example below ..

gridViewPublishers.DataSource.GetType().ToStirng() =  System.Data.DataView

Is it really strange?

Protected Sub gridViewPublishers_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridViewPublishers.Sorting

Label1.Text = gridViewPublishers.DataSource.GetType().ToString()

Dim m_DataTable As DataTable = gridViewPublishers.DataSource

   If Not m_DataTable Is Nothing Then

   Dim m_PageIndex As Integer = gridViewPublishers.PageIndex

   Dim m_SortDirection As String = GetSortDirection()

   Dim m_DataView As New DataView(m_DataTable)

   m_DataView.Sort = e.SortExpression &

" " & m_SortDirection

   gridViewPublishers.DataSource = m_DataView

   gridViewPublishers.DataBind()

   gridViewPublishers.PageIndex = m_PageIndex

   End If

End Sub

 

Jangyoung
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 7:27:55 PM

0

Hello, again.

I found something is really strange.

if I just test the example below

Protected Sub gridViewPublishers_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridViewPublishers.Sorting

Label1.Text = gridViewPublishers.DataSource.GetType().ToString()

End Sub

gridViewPublishers.DataSource.GetType().ToStirng() =  System.Data.DataTable

-------------------------------------------------------------------------------------------------------------

Anyway, I changed my source the example below

However, sorting does not work.

Only current page is sorted but if I clicked the next page, data does not sort at all.

what is the my problem?

 

Protected Sub gridViewPublishers_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles gridViewPublishers.Sorting

Label1.Text = gridViewPublishers.DataSource.GetType().ToString()

Dim m_DataTable As DataTable

If Label1.Text = "System.Data.DataView" Then

m_DataTable =

CType(gridViewPublishers.DataSource, System.Data.DataView).Table

Else

m_DataTable = gridViewPublishers.DataSource

End If

 

If Not m_DataTable Is Nothing Then

Dim m_PageIndex As Integer = gridViewPublishers.PageIndex

Dim m_SortDirection As String = GetSortDirection()

Dim m_DataView As New DataView(m_DataTable)

m_DataView.Sort = e.SortExpression &

" " & m_SortDirection

gridViewPublishers.DataSource = m_DataView

gridViewPublishers.DataBind()

gridViewPublishers.PageIndex = m_PageIndex

End If

End Sub

 

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/10/2006 10:36:48 PM

0

Jangyoung:
I just found that

Data type is System.Data.DataView, not System.Data.DataTable.

All you should have to do is change the following line:

m_DataTable As DataTable = gridViewPublishers.DataSource

to

m_DataView As DataView = gridViewPublishers.DataSource

and then modify the code accordingly.

HTH,
Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
Jangyoung
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/11/2006 1:48:41 PM

0

Dear Ryan,

Thank you for your time.

The example on your site works for the first page.

But when you click page 2 the sorting from the page 1 does not continue to page 2

For example, page 1 sorted by Publisher ID

from 1 - 25  but page 2 start at 426.

I think page 2 is supposed to start at 26  to 50..  Is that right?

 hopefully,  not to bother you..Thanks a lot.

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource4/11/2006 2:08:15 PM

0

Jangyoung:
The example on your site works for the first page.

But when you click page 2 the sorting from the page 1 does not continue to page 2

See http://forums.asp.net/2/1254336/ShowThread.aspx#1240547

Good luck.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
CDavidOrr
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/26/2006 6:49:36 PM

0

Hi.  I appreciate all your work to help make things easier on us.  I checked out the code via your supplied link and have discovered that there is still a problem that I am experiencing in my code as well.  After the grid is displayed, click on the column header for Publisher ID and the grid sorts by that column.  However, if you then click on page 2, the grid displays the second page but it is no longer sorted by Publisher ID.

Do you know how to avoid this problem?

Thanks,

David

CDavidOrr
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/26/2006 6:58:58 PM

0

Sorry, ignore my previous post.  I didn't notice the additional pages to the thread.

Thanks.

186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|


Free Download:


Web:
Sorting & Paging In GridView ? - ASP.NET Forums If you are using DataSet then this may help you. http://ryanolshan.com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource ...
Trying to use the FAQ " Sorting and paging in the GridView control ... http://ryanolshan.com/articles/c-gridview-sorting-paging-w-o-a-datasourcecontrol -datasource/. Regards,Vinz "Code, Beer and Music" that's my ...
[web refference]C# GridView Sorting/Paging w/o a DataSourceControl ... 2008年6月19日 ... /c-gridview-sorting-paging-woa-datasourcecontrol-datasource/C# ... on a GridView control without using a DataSourceControl DataSource ...
gridview sorting - Dot Net Search Engine swicki - powered by eurekster C# GridView Sorting/Paging w/o a DataSourceControl DataSource . ... ryanolshan. com/articles/c-gridview-sorting-paging-w-o-a-data. ... How to use sorting in GridView in ASP.Net. Add image in grid header to indicate sort direction. ...
gridview paging issue - ASP.NET Forums hi , iam using a gridview with paging ,but paging doesnot works ,it shows ... /c -gridview-sorting-paging-w-o-a-datasourcecontrol-datasource/ ...

HOW TO: Using sorting / paging on GridView w/o a DataSourceControl ... NET Forums If you are using DataSet then this may help you. http://ryanolshan. com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource . ...






access denied creating a file

custom wizard how-to not using a createuserwizard

arguments of matrix

developing a specialty browser proxy

documentation

datetimeformatinfo problem

integration between asp and asp.net

timer handle in c#

strange compile problem

adding/approving friends script in asp.net 2.0

fileupload control style

when will fire session end event?

help !!!!!! accessing shared folder on network

the stupid and useless span wrapper on web controls...

url is changed from "\filename.aspx" to "%2ffilename.aspx" - help !!

setting up cell height

system.reflection.ambiguousmatchexception

configurationmanager not reading connectionstring

help selectedweek on the calendar control

how can i call a button's onclick event in code?

how to go to the bottom of the page on every page load

anyone knows where the asp.net manual is?

supported by the .net compact framework.

how to create customererror page for remote view of all errors

uploading files to sql database

how to include the correct htm file in aspx depending on querystring?

server transfer vs response.redirect.

how can i read my mails from a pop3 mail server using asp.net

send password message

help a beginner...

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT