Custom Paging .Net 2.0 to .Net 3.0

 I have a web app written in VS 2005 that uses griviews with custom paging and sorting done as follows.

 <asp:GridView  ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="rec_id" BorderColor="White" BackColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None"
AllowPaging="True" AllowSorting="True" PageSize="20" OnSorting="Gvemp_sort" OnPageIndexChanging="gvemp_page"
EmptyDataText="There are no classes listed at this time." CssClass="Grid">
<Columns>
<asp:CommandField SelectText="Sessions" ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" ControlStyle-CssClass="GridA"/>
<asp:BoundField DataField="classtitle" HeaderText="Class Title" SortExpression="classtitle asc" />
<asp:BoundField DataField="classdesc" HeaderText="Description" />
<asp:ButtonField DataTextField="required" SortExpression="required asc" CommandName="empsel" HeaderText="Required" ControlStyle-CssClass="GridA"/>
<asp:BoundField DataField="test" HeaderText="Test" SortExpression="test asc" />
<asp:BoundField DataField="display" HeaderText="Display" SortExpression="display asc"/>
<asp:BoundField DataField="location" HeaderText="Plant" SortExpression="location asc"/>
<asp:BoundField DataField="type" HeaderText="Type" SortExpression="type asc"/>
<asp:BoundField DataField="acnt" HeaderText="Att Cnt" />
<asp:BoundField DataField="ts" HeaderText="Created By" />
</Columns>
<RowStyle CssClass="GridRow" />
<SelectedRowStyle CssClass="GridSelRow" />
<PagerStyle CssClass="GridPager" />
<HeaderStyle CssClass="GridHead" />
<PagerSettings Mode="NumericFirstLast" />
<EmptyDataRowStyle CssClass="GridEmpty" />
</asp:GridView
Function SortOrder(ByVal Feild As String) As String
If
Feild = ViewState("SortOrder").ToString() Then
SortOrder = Replace(Feild, "asc", "desc")
Else
SortOrder = Replace(Feild, "desc", "asc")
End If
End Function

Sub
Gvemp_page(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GetDataReader(ViewState("SortOrder").ToString)
End Sub

Sub
Gvemp_sort(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
GridView1.PageIndex = 0
GetDataReader(SortOrder(e.SortExpression.ToString))
End Sub
  
Sub GetDataReader(ByVal ColumnOrder As String)
Try
'Assign ColumnOrder to viewstate
ViewState("SortOrder") = ColumnOrder

Dim fe As Encryption64 = New Encryption64
Dim strConn As String = fe.DecryptFromBase64String(AppSettings("ConnString"), "*******")
Dim conn1 As New SqlClient.SqlConnection(strConn)

Dim cmdLoadData As New SqlClient.SqlCommand("********", conn1)
cmdLoadData.CommandType = CommandType.StoredProcedure

With cmdLoadData
.Parameters.Add(New SqlClient.SqlParameter("@sb", SqlDbType.VarChar = 20))
.Parameters("@sb").Value = Trim(ColumnOrder)
End With

'Creat datatable
Dim DataReaderTable As New DataTable
Dim dc0 As New DataColumn("Rec_id", GetType(Object))
Dim dc1 As New DataColumn("Classtitle", GetType(String))
Dim dc2 As New DataColumn("ClassDesc", GetType(String))
Dim dc3 As New DataColumn("Required", GetType(String))
Dim dc4 As New DataColumn("TS", GetType(String))
Dim dc5 As New DataColumn("Display", GetType(String))
Dim dc6 As New DataColumn("Type", GetType(String))
Dim dc7 As New DataColumn("Location", GetType(String))
Dim dc8 As New DataColumn("Test", GetType(String))
Dim dc9 As New DataColumn("ACnt", GetType(String))
With DataReaderTable
.Columns.Add(dc0)
.Columns.Add(dc1)
.Columns.Add(dc2)
.Columns.Add(dc3)
.Columns.Add(dc4)
.Columns.Add(dc5)
.Columns.Add(dc6)
.Columns.Add(dc7)
.Columns.Add(dc8)
.Columns.Add(dc9)
End With

conn1.Open()
Dim datareader As SqlClient.SqlDataReader
datareader = cmdLoadData.ExecuteReader
While datareader.Read
Dim dr As DataRow = DataReaderTable.NewRow
With dr
dr(0) = datareader(0)
dr(1) = datareader(1)
dr(2) = datareader(2)
dr(3) = datareader(3)
dr(4) = datareader(4)
dr(5) = datareader(5)
dr(6) = datareader(6)
dr(7) = datareader(7)
dr(8) = datareader(8)
dr(9) = datareader(9)
End With
DataReaderTable.Rows.Add(dr)
End While
'Close datareader
datareader.Close()
'Close connection
conn1.Close()
Dim source As DataView = DataReaderTable.DefaultView
source.Sort = ColumnOrder
'Bind datagrid from arraylist
GridView1.DataSource = source
GridView1.DataBind()
        Catch ex As Exception
lblError.Text = "GetDataReader " & ex.ToString
End Try
End Sub
 
 This works perfectly in VS 05. I do the same thing in VS 08 but it does not work. No errors but it just doesn't function. Any ideas as to any differences between VS 05 and VS 08?
  
 
0
melvincureton
6/26/2008 10:44:04 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1340 Views

Similar Articles

[PageSpeed] 32
Get it on Google Play
Get it on Apple App Store

 Any ideas as to why this would work in .net 2.0 and not work in .net 3.0?

0
melvincureton
6/30/2008 7:15:56 PM

Hi melvincureton,

Try to use breakpoint to find the problem. Here is another sample for sorting and paging in GridView:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = GetStudent("select * from student").Tables[0];
            GridView1.DataBind();
        }
    }

    public DataSet GetStudent(string query)
    {
        SqlConnection conn = new SqlConnection(@"Server=(local)\SQLEXPRESS;Integrated Security=SSPI;Database=test;Persist Security Info=True");
        SqlCommand cmd = new SqlCommand(query, conn);
        conn.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        conn.Close();
        return ds;
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
       {
           GridView1.DataSource = SortDataTable(GetStudent("select * from student").Tables[0] as DataTable, true);
           GridView1.PageIndex = e.NewPageIndex;
           GridView1.DataBind();
       }
  
     private string GridViewSortDirection
       {
           get { return ViewState["SortDirection"] as string ?? "ASC"; }
           set { ViewState["SortDirection"] = value; }
       }

      private string GridViewSortExpression
      {
          get { return ViewState["SortExpression"] as string ?? string.Empty; }
          set { ViewState["SortExpression"] = value; }
      }
 
      private string GetSortDirection()
      {
          switch (GridViewSortDirection)
          {
              case "ASC":
                  GridViewSortDirection = "DESC";
                  break;
              case "DESC":
                  GridViewSortDirection = "ASC";
                  break;
          }
 
          return GridViewSortDirection;
      }
 
      protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
      {
          if (dataTable != null)
          {
              DataView dataView = new DataView(dataTable);
              if (GridViewSortExpression != string.Empty)
              {
                  if (isPageIndexChanging)
                  {
                      dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
                  }
                  else
                  {
                      dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
                  }
              }
              return dataView;
          }
          else
          {
              return new DataView();
          }
      }
 
      protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
      {
          GridViewSortExpression = e.SortExpression;
          int pageIndex = GridView1.PageIndex;
          GridView1.DataSource = SortDataTable(GetStudent("select * from student").Tables[0] as DataTable, false);
          GridView1.DataBind();
          GridView1.PageIndex = pageIndex;
      }

    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        DetailsView1.DataSource = GetStudent("select * from student where ID=" + GridView1.DataKeys[e.NewSelectedIndex].Value).Tables[0];
        DetailsView1.DataBind();
    }

Thanks,


Qin Dian Tang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Qin
7/1/2008 9:29:35 AM

 Hope this will guide you for the Paging in the GridView..

Paging in GridView 


"A conclusion is where you got tired of thinking.
Be different. Think "

Remember to click “Mark as Answer” on the post If you get answer from my post(s) !

Thanks Guys
------------
Pushkar
0
Pushkar
7/1/2008 9:36:07 AM
Reply:

Similar Artilces:

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

.NET 3.0 or .NET 2.0?
I'm going to move my exiting software to .net soon. I'm just wondering if I should wait for the .NET 3.0 framework to be released or if I can start with the 2.0 now? I'd say you can go ahead and move your code to .Net 2.0 as .Net 3.0 uses the CLR version 2.0.Basically, .net 3.0 is .net 2.0 PLUS some new features for presentation (GUI), communication and workflow process.  So the compiler as well as the language features used by the 2.0 runtime will be the same in 2.0 and 3.0"Never argue with an idiot; He will drag you down to his level and beat you with experienc...

Will AJAX Extensions 1.0 (for .NET 2.0) be affected by .NET 3.0?
Hello all,I have a web server that has a couple of site running using .NET 2.0 with the AJAX Extensions 1.0 (but not the ControlKit) and I need to install another Web App site that uses .NET 3.0. I need to know if installing .NET 3.0 will affect the sites that currently use 2.0 and the AJAX Extensions 1.0 as these sites are live and any down time would get me in the @~!£$.If there are issues, are there any work arounds? Many Thanks in advance  The .net Framework 3.0 and 3.5 add features to the .net framework 2.0 so installing the additional framework should not cause any pro...

.NET 2.0 and .NET 3.0 Running parallel
Are there any known issues for both of the frameworks running in parallel on same machine Also searched on the web but would like to know complete reference, before I dirty my hands on the 3.0.Any help is appreciated.regardsRaheel Hussain--------------------------------Blog: http://www.dnfug.com/web/blogs/raheel/URL: http://www.raheelhussain.com/--------------------------------This posting is provided "AS IS" with no warranties, and confers no rights. The 2.0 and 3.0 frameworks don't run separately, they run together.  Think of .NET 3.0 as an extension of 2.0, ...

Application created in new version of .NET (3.0 or 3.5) can use the library created in older version of .NET(i.e.-1.0 or 2.0)?
Hi All, I am using Visual Studio .NET compiler for compiling my application . We have plugins (as library) which the user can write by their own in .NET . We are building our code in Visual Studio 2005 but we have already some plug-ins which are written in previous versions of Visual Studio (i.e. 2002 and 2003). Is these plug-ins will work with the new build of the application or I need to build these plug-ins as well in Visual Studio .NET 2005. These plugins are created as library. Is their any differences between .NET 1.0, 2.0 and 3.0 because of which the old libraries (created in o...

How can i upgrade my project from .net 2.0 to .net 3.0
I have been developing my project in .net 2.0 and and its already deployed for testing. Its not yet in use but its already deployed for testing purposes. Then i realised that i already have .net 3.0 installed both on my developement computer and on our production sever posiibly through these microsoft updates because i did not install .net 3.0 manually, i just found them in the installed programs. So how can i configure this project and all the applications that i will develop in future to use .net 3.0 instead of 2.0 that iam currently using. Basically what i want to do is move my applicati...

Error with using .Net 3.0 instead of .Net 2.0
Hi,  I have recently made a website in microsoft visual web developer 2005.  When I have uploaded my site to my host I am having trouble.  when I visit the page www.amcnewzealand.co.nz I get an error message.  My web hosting company does not support .net 3.0 but instead use .net 2.0.  My website is made with file extensions .aspx.  I am usure how to tell what version of .net I am using and wether this is the only cause.  At first there was a 403 error occuring. Help would be much appreciated as I have been struggling with this for some time. The version...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

I installed .net 2.0 but there is .net 3.0 in the add or remove programs list as well, why
Hi, installed .net 2.0 "i know thats what iam running" but recently i found .net 3.0 as well when browsing the add or remove programs list. .net 2.0 is in the list as well but i dont remember a day i installed .net 3.0. The questions are how did it install. What version of .net is running on my system then. --------------------------------------------------No Project Too Eazy.-------------------------------------------------- >>The questions are how did it install.  Are you running Vista?  (.net 3.0 comes with Vista) >>What&...

Access .Net 2.0 Application from .Net 2.0 Web Site
I need to populate a specific form in a .Net desktop application from a .net web application.  Is there an easy way to go about this? Hi, Based on my understanding, you want to start an executable application from your ASP.NET websit, right? We can invoke Process.Start method (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx) to launch an executable application from ASP.NET application. Note: Please keep in mind, the ASP.NET application is running on the server, so it will start the executable application that exists in the server.   I look...

Clickonce deployment anyone (DW.NET 2.0 and .NET 2.0)?
I saw someone had posted a question about this already, and there were no responses. So I am hoping that this will get some. We had problems with the previous version of DW.NET 1.5 + VS2003 when attempting to deploy applications via a web server. So many problems that we eventually decided to run off a network drive (which is OK if your user base doesn't roam around the country). Anyway, we gave up on DW.NET, and started to use the datagrid control. Since then, much has changed. Our development team now has VS2005 professional and may start using DW.NET 2.0 (pending my inv...

.NET 2.0 Data Connection (.NET 2.0 Beta Data Provider)
I have installed the .NET 2.0 Beta Data Provider, in the server explorer in Visual Studio 2005 I have tried to connect to this provider but I can not see it in the list. Is there something else you need to do to see this other than what is in the instructions or is this not supported yet? Hi Dean, I assume you mean ASE ADO.NET 2.0 Beta. I'm attaching the html readme for this product that you should have from downloading it. Are you talking about using Server Explorer to see the Provider? This functionality isn't working yet and should be available on GA or shortly ...

How to change .Net framework from Version=3.5.0.0 back to Version=2.0.0.0 ?
Hello, Can anyone tell me how to change .Net framework from Version=3.5.0.0 back to Version=2.0.0.0 ? I have 2 different versions of Visual Studio: VS2005 and VS2008. One is running in .NET framework 2.0.0.0 and the other one is running in framework version 3.5.0.0.  When run the web application that is in framework Version 2.0.0.0 in VS2005, I get the error below.  In the web.config of the project, there is no 'System.Core....' assembly listed in the Assemblies section and all other system assemblies are in framework version 2.0.0.0. Also I checked the Mic...

Web resources about - Custom Paging .Net 2.0 to .Net 3.0 - asp.net.presentation-controls

Customs - Wikipedia, the free encyclopedia
The movement of people into and out of a country is normally monitored by immigration authorities, under a variety of names and arrangements. ...

Custom - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

It's coming: the custom and cut-price coffins boom
Forget the traditional silver casket, now you can get a budget coffin or one decorated in NRL colours.

Chrome 48 Beta brings custom buttons on notifications, casting from the web, more
With Chrome 47 currently rolling out to desktops and Android, Google has announced the Chrome 48 Beta and the new features that will come with ...

Dow Jones CEO Says Company Has Played Catch-Up On Custom Content, Isn't Worried About Ad Blocking
... and Communications Conference. "We're now making up for lost time." "There is a bit of a revolution going on in advertising, led by this custom ...

Sapphire Readies Nitro R9 Fury: Custom Design and Enhanced Performance
... is preparing to release its new graphics card — the Nitro R9 Fury — based on AMD’s Fiji graphics processing unit that features its own custom ...

Chrome Beta v48 adds custom notification buttons, Presentation API support and more
... other compatible devices. This version now allows mobile sites to present to Google Cast devices. Also new in this update is support for custom ...

Want some good vibrations? Set up custom vibrations for iPhone
Creating custom vibrations on your iPhone makes it easy to separate your notifications and ensures you don’t miss a notification, even when your ...

Apple adds shuffle option for custom Apple Music playlists on Apple TV
Apple recently rectified a niggling oversight in its somewhat slipshod Apple Music app for tvOS, adding a shuffle option for created playlists ...

Microsoft is making a custom version of Windows 10 for the Chinese government
Microsoft is working with the Chinese government to make a custom version of Windows 10, according to a blog post . The software will be used ...

Resources last updated: 12/18/2015 11:33:50 AM