DataGrid Paging makes DataGrid Disappear

S

smithb1028

I have a simple DataGrid and trying to get paging to work. I
orginially want to use this in an AJAX UpdatePanel, but I moved it out
of it until I get it to work.

This is the DataGrid in the ASPX:

<asp:DataGrid ID="dgActiveVisits" AutoGenerateColumns="true"
AllowPaging="true" PageSize="5" Width="100%" BorderWidth="0"
CellPadding="3" CellSpacing="0"
OnPageIndexChanged="dgActiveVisits_PageIndexChanged" runat="server">
<HeaderStyle BackColor="Gray"
ForeColor="White" />
</asp:DataGrid>

The C# code behind:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dgActiveVisits.CurrentPageIndex = 0;
BindData();
}
}

protected void dgActiveVisits_PageIndexChanged(object sender,
DataGridPageChangedEventArgs e)
{
dgActiveVisits.CurrentPageIndex = e.NewPageIndex;
BindData();
}

void BindData()
{
DataTable dt = new DataTable();
// removed DataTable setup, has 15 rows

dgActiveVisits.DataSource = dt;
dgActiveVisits.DataBind();
}

When the page first loads, it loads the first page of data just fine.
But when I click Next, the entire DataGrid just disappears... At first
I thought there was an issue with the UpdatePanel, but after taking it
out of the UpdatePanel it still displays this same behavior... I
looked all over the internet and followed their examples exactly...

Any help would be greatly appreciated...
 
S

smithb1028

Also, you'll notice on the Page_Load it sets the current index to 0.
If I change that to 1 or 2, it does display the appropriate page of
data on first load. But again, moving back or next causes the entire
DataGrid to disappear...

The only thing I'm doing differently from previous apps, is I have
added the AJAX extensions to the web.config and I've installed SP1 for
VS 2005.

I can not, for the life of me, see the problem. Any help is much
appreciated...


Brad
 
M

Mark Rae

I can not, for the life of me, see the problem. Any help is much
appreciated...

Put a breakpoint on the line

dgActiveVisits.DataSource = dt;

and interrogate the dt.Rows.Count property...
 
S

smithb1028

So I copied paste the code into a new Web Form and, of course, it
worked... So I'll just build the rest around it now... I have some
other issues but will post them in a new thread because they are
related to different controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top