Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2007, 11:40 AM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default datagrid does not display next page

I have page which contains dropdownlist items. When user selects a value, I display a datagrid. Works fine. But when I move to the next page on the datagrid, the datagrid does not display. I know for sure there are records in the next page. Can someone tell me what could be wrong?

 
Old July 19th, 2007, 02:43 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Is the datagrid not showing up at all?

Is the display of the datagrid defendant on an event from the dropdownlist?

-Peter
 
Old July 19th, 2007, 03:18 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Once I select values from dropdownlist the firstpage shows up on datagrid. When I move to next page I don't see the datagrid (even though next page has rows).
Do you want me to post the code?

 
Old July 19th, 2007, 03:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Sure, but please post just the relevant code.
 
Old July 19th, 2007, 03:45 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<asp:datagrid id="DataGrid1" runat="server" AllowCustomPaging="True" PageSize="1" AllowPaging="True"
                                            AutoGenerateColumns="False">
    <Columns>
        <asp:BoundColumn DataField="EMPID" HeaderText="EMP ID">
            <HeaderStyle Font-Underline="True" Font-Names="verdana"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="LNAME" HeaderText="Last Name">
            <HeaderStyle Font-Underline="True"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="PHONENO" HeaderText="Phone Number">
            <HeaderStyle Font-Underline="True"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="INSDATE" HeaderText="Req. Date">
            <HeaderStyle Font-Underline="True"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="APPROVEDDATE" HeaderText="App. Date">
            <HeaderStyle Font-Underline="True"></HeaderStyle>
        </asp:BoundColumn>
        <asp:TemplateColumn>
            <ItemTemplate>
                <asp:CheckBox id="Checkbox1" Text="Delete" runat="server"></asp:CheckBox>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
    <PagerStyle Font-Size="8pt" Font-Bold="True" HorizontalAlign="Right" Position="TopAndBottom"></PagerStyle>
</asp:datagrid>
<PagerStyle BackColor="Navy" ForeColor="White" Font-Size="8pt"
Font-Bold="True" HorizontalAlign="Right"
NextPageText="Next >" PrevPageText="< Prev"
Position="TopAndBottom" />

Code behind:
void BindGrid()
{
    myConnection = new OracleConnection(ConfigurationSettings.AppSettings["oraClientConnStr"]);
    try
    {
        string classCode = DropDownListCourse.SelectedValue;
        string locCode = DropDownListLoc.SelectedValue;
        mySelectQuery = "SELECT * from Training.trschedules_view where classcode = " + classCode;
        myConnection.Open();
        myCommand = new OracleCommand(mySelectQuery, myConnection);
        myReader = myCommand.ExecuteReader();
        if (myReader.HasRows)
        {
            DataGrid1.DataSource=myReader;
            DataGrid1.DataBind();
        }
    }
    finally
    {
        myConnection.Close();
    }

}

private void Button1_Click(object sender, System.EventArgs e)
{
BindGrid();
}

 
Old July 19th, 2007, 03:56 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What about the page index changed event? You need to rebind when that happens.

Hmm. You have custom paging turned on. I'm not sure how this will affect this problem.

-Peter
 
Old July 19th, 2007, 03:56 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I am also wondering... with a page size of 1 why bother with a datagrid? Why not a simpler form view? Do you only want to show 1 record at a time?

-Peter
 
Old July 19th, 2007, 04:21 PM
Authorized User
 
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed pagesize to 10 it does same thing. Should I remove custom paging?

 
Old July 20th, 2007, 07:48 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you use custom paging you need to provide the right page data and the page count. This is useful if you have a query that handles the paging. A good example of this would be if you have a huge table, lets say 1 million records. The normal behavior of the paging .NET controls is to take all the data from the query and determine the page count based on your page size and show the records for that page. This means that you are transferring 1 million records EVERY TIME you bind the grid. This is very inefficient. So you write a query/sproc that calculates the pages and the returns just the records for that page (say 10). But now you need to convey to the control how many pages there are and pass the current page index to the query.

Initially, start simple, turn custom paging off and let the control handle the paging logic for you while you are getting it working, then take it from there.

-Peter
 
Old July 22nd, 2007, 12:28 AM
Friend of Wrox
 
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Default

me too can't find the PageIndexChange event!

try this ..

    protected void grd_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            grd.PageIndex = e.NewPageIndex;
            grd.DataSource = ds.Tables[0];
            grd.DataBind();
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }


Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"





Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom paging in Datagrid with datagrid page count madhusrp ASP.NET 1.0 and 1.1 Professional 12 June 2nd, 2008 01:15 PM
How to Display an Empty DataGrid on Page Load jigsawcube1 General .NET 1 September 13th, 2007 10:00 PM
Datagrid display Lovehead VB.NET 2002/2003 Basics 1 January 20th, 2007 05:12 PM
Probelm in DataGrid Display su C# 1 December 8th, 2006 05:00 AM
Datagrid display deadrocker .NET Web Services 1 February 12th, 2005 07:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.