Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 19th, 2007, 11:40 AM
Authorized User
 
Join Date: Oct 2004
Location: , , .
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?

Reply With Quote
  #2 (permalink)  
Old July 19th, 2007, 02:43 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #3 (permalink)  
Old July 19th, 2007, 03:18 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
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?

Reply With Quote
  #4 (permalink)  
Old July 19th, 2007, 03:36 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Sure, but please post just the relevant code.
Reply With Quote
  #5 (permalink)  
Old July 19th, 2007, 03:45 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
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();
}

Reply With Quote
  #6 (permalink)  
Old July 19th, 2007, 03:56 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #7 (permalink)  
Old July 19th, 2007, 03:56 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #8 (permalink)  
Old July 19th, 2007, 04:21 PM
Authorized User
 
Join Date: Oct 2004
Location: , , .
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?

Reply With Quote
  #9 (permalink)  
Old July 20th, 2007, 07:48 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
Reply With Quote
  #10 (permalink)  
Old July 22nd, 2007, 12:28 AM
Friend of Wrox
 
Join Date: Aug 2006
Location: Amman, , Jordan.
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"
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:28 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.