The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by dasousa]

I have coded the DataGrid example in 8.3.4. It worked fine.

I then added the PageSize="10" and AllowPaging="true" attributes to the
asp:dataGrid. My problem is that only the first 10 rows display. Even when I
click the next page symbol (>smilie, the first 10 rows are not changed.

Is there anything else that needs to be done in order to get paging to work?
I am using XP Pro with the .Net Framework SP1 and IE 6.0.

Thanks,

Dave
import-bot (20211) [Avatar] Offline
#2
Re: DataGrid Paging
[Originally posted by taka]

Hi Dave,

How about this one?

<!-- dataform.aspx -->

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">

protected override void OnLoad(EventArgs e) {

base.OnLoad(e);

gamesGrid.DataSource = CreateDataSource();
gamesGrid.DataBind();

}

ICollection CreateDataSource() {
SqlConnection con =
new SqlConnection(
@"server=(local);database=poker;uid=sa;pwd=12345");

SqlDataAdapter com =
new SqlDataAdapter("select * from games", con);

DataSet ds = new DataSet();
com.Fill(ds, "games");

DataView dv = new DataView(ds.Tables["games"]);
return dv;
}

void Grid_Change(Object sender, DataGridPageChangedEventArgs e){
// Set CurrentPageIndex to the page the user clicked.
gamesGrid.CurrentPageIndex = e.NewPageIndex;

// Rebind the data.
gamesGrid.DataSource = CreateDataSource();
gamesGrid.DataBind();
}

</script>

<html><head><title>DataGrid ASP.NET App</title></head>
<body>
<h1>DataGrid ASP.NET Application</h1>
<form runat="server">
<asp:dataGrid>
id="gamesGrid"
BackColor="Gainsboro"
BorderColor="black"
CellPadding="5"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
Font-Bold="true"
HeaderStyle-BackColor="lightGreen"

EnableViewState="true"

AllowPaging="true"
PageSize="10"
OnPageIndexChanged="Grid_Change"

runat="server" />
</form>
</body>
</html>

Maybe, we have the other ways.
Fergal?

Best regards,
Taka
import-bot (20211) [Avatar] Offline
#3
Re: DataGrid Paging
[Originally posted by fgrimes]

Taka... your way looks just fine to me.
Fergal
import-bot (20211) [Avatar] Offline
#4
Re: DataGrid Paging
[Originally posted by dasousa]

Thank you for your response. This worked well.

Fergal, the only disappointment that I have had in reading your book is that I
have finished it! It was excellent, and I felt compelled to post my first
review on Amazon. Thanks.

Dave

P.S. The OpenWave SDK looks very interesting. Have you had good experience
with it?

> Hi Dave,
>
> How about this one?
>
> <!-- dataform.aspx -->
>
> <%@ Page Language="C#" Debug="true" %>
> <%@ Import Namespace="System.Data" %>
> <%@ Import Namespace="System.Data.SqlClient" %>
>
> <script runat="server">
>
> protected override void OnLoad(EventArgs e) {
>
> base.OnLoad(e);
>
> gamesGrid.DataSource = CreateDataSource();
> gamesGrid.DataBind();
>
> }
>
> ICollection CreateDataSource() {
> SqlConnection con =
> new SqlConnection(
> @"server=(local);database=poker;uid=sa;pwd=12345"smilie;
>
> SqlDataAdapter com =
> new SqlDataAdapter("select * from games", con);
>
> DataSet ds = new DataSet();
> com.Fill(ds, "games"smilie;
>
> DataView dv = new DataView(ds.Tables["games"]);
> return dv;
> }
>
> void Grid_Change(Object sender, DataGridPageChangedEventArgs e){
> // Set CurrentPageIndex to the page the user clicked.
> gamesGrid.CurrentPageIndex = e.NewPageIndex;
>
> // Rebind the data.
> gamesGrid.DataSource = CreateDataSource();
> gamesGrid.DataBind();
> }
>
> </script>
>
> <html><head><title>DataGrid ASP.NET App</title></head>
> <body>
> <h1>DataGrid ASP.NET Application</h1>
> <form runat="server">
> <asp:dataGrid>
> id="gamesGrid"
> BackColor="Gainsboro"
> BorderColor="black"
> CellPadding="5"
> CellSpacing="0"
> Font-Name="Verdana"
> Font-Size="8pt"
> Font-Bold="true"
> HeaderStyle-BackColor="lightGreen"
>
> EnableViewState="true"
>
> AllowPaging="true"
> PageSize="10"
> OnPageIndexChanged="Grid_Change"
>
> runat="server" />
> </form>
> </body>
> </html>
>
> Maybe, we have the other ways.
> Fergal?
>
> Best regards,
> Taka
import-bot (20211) [Avatar] Offline
#5
Re: DataGrid Paging
[Originally posted by fgrimes]

Hi Dave,

>> Fergal, the only disappointment that I have had in reading your book is
that >> I have finished it! It was excellent, and I felt compelled to post my
first
>> review on Amazon. Thanks.

I'm glad you enjoyed it... and thanks for the review. Every little helps.

>> P.S. The OpenWave SDK looks very interesting.
>> Have you had good experience with it?

I haven't looked at it... except for the phone emulator, which worked nicely.

Thanks again...
Fergal
import-bot (20211) [Avatar] Offline
#6
Re: DataGrid Paging
[Originally posted by taka]

Hi Fergal,

I tried to create dataform.aspx with VisualStudio.NET.
I dare not upload the codes generated by VS.NET, this time.
Following the VS.NET's manner, I could make the project, very quickly.
But a bunch of codes were generated.
Using VS.NET seems to be Easy to Generate but Difficult to Read/Maintain.
Tough Stuff!

Your next book should be, "Visual Studio.Net for Programmers"!

Best regards,
Taka