Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / August 2003

Tip: Looking for answers? Try searching our database.

DataGrid Paging??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DaMan - 27 Aug 2003 19:46 GMT
I have code that builds  a dataset and connects it to a datagrid. I set up
paging but something is broke.
I can do a pagecount property and it returns 6
I tried to use the simple paging example in MSDN and it only will display
the first page, if I hit the next page button it (the datagrid is not
displayed.)
I can do it manually but only once.

label.text = DataGrid1.PageCount   <<returns 6
DataAdapter.Fill(tmpDataSet)
DataGrid1.CurrentPageIndex = 0
DataGrid1.DataBind()
*********Great, displays 1 page****
I can set pageindex to 1 or 2 or 3 or ...6 and get the correct data for that
page....

BUT, I can only do this once, if I display, say, page one or whatever, and
change the pageindex to another page, the datagrid disappears.. I must be
missing something, but I cant figure out what....
Ex Code in PAGE_LOAD

label.text = DataGrid1.PageCount   <<returns 6
DataAdapter.Fill(tmpDataSet)
DataGrid1.CurrentPageIndex = 0   << I can set to any nbr up to 5 and get
that page..
DataGrid1.DataBind()
and create a button that simply changes page index
DataGrid1.CurrentPageIndex = 2  << no number works here now after page loads
DataGrid1.DataBind()
********nothing is displayed when I hit button

Please Help  Thanks  KT
"Mike Moore [MSFT]" - 27 Aug 2003 23:01 GMT
Hi,

You wrote that you're using the page up and down keys. Here is how I
created a grid which uses the page up & down keys. Please let me know if
this code snippet answers your question.

*** ASPX page
     <script>
function window_onkeydown() {
  if (event.keyCode==33 || event.keyCode==34)
  {
     Form1.UpDown.value=event.keyCode;
     Form1.submit();
  }
}
     </script>
  </HEAD>
  <body onkeydown="return window_onkeydown()">

*** Code-behind
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
     If Not IsPostBack Then
        DataGrid1.AllowPaging = True
        DataGrid1.PageSize = 10
        DataGrid1.PagerStyle.Mode = PagerMode.NextPrev
        DataGrid1.PagerStyle.NextPageText = "Next"
        DataGrid1.PagerStyle.PrevPageText = "Prev"
        Bind()
     End If
     If Request.Form("UpDown") <> "" Then
        If Request.Form("UpDown") = 33 Then
           If DataGrid1.CurrentPageIndex < DataGrid1.PageCount - 1 Then
              DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex + 1
           End If
        Else
           If DataGrid1.CurrentPageIndex > 0 Then
              DataGrid1.CurrentPageIndex = DataGrid1.CurrentPageIndex - 1
           End If
        End If
     End If
     Bind()
  End Sub

  Private Sub Bind()
     Dim connectionString As String = "server='localhost';
trusted_connection=true; Database='pubs'"
     Dim cnn As SqlConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
     Dim queryString As String = "SELECT [authors].[au_id],
[authors].[au_lname], [authors].[au_fname] FROM [authors]"
     Dim da As SqlDataAdapter = New SqlDataAdapter(queryString, cnn)
     Dim ds As New DataSet()
     da.Fill(ds, "pubs")
     DataGrid1.DataSource = ds.Tables("pubs")
     DataGrid1.DataBind()
     da.Dispose()
     cnn.Close()
     cnn.Dispose()
  End Sub

  Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid1.PageIndexChanged
     DataGrid1.CurrentPageIndex = e.NewPageIndex
     Bind()
  End Sub

Thank you, Mike Moore
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
> From: "DaMan" <mail@kyndall.com>
> Subject: DataGrid Paging??
[quoted text clipped - 9 lines]
> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
> Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:6385
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
>
[quoted text clipped - 30 lines]
>
> Please Help  Thanks  KT
K T - 28 Aug 2003 15:45 GMT
Yes, it worked, Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.