p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   datagrid does not display next page (http://p2p.wrox.com/showthread.php?t=60278)

vhrao July 19th, 2007 11:40 AM

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?


planoie July 19th, 2007 02:43 PM

Is the datagrid not showing up at all?

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

-Peter

vhrao July 19th, 2007 03:18 PM

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?


planoie July 19th, 2007 03:36 PM

Sure, but please post just the relevant code.

vhrao July 19th, 2007 03:45 PM

<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();
}


planoie July 19th, 2007 03:56 PM

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

planoie July 19th, 2007 03:56 PM

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

vhrao July 19th, 2007 04:21 PM

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


planoie July 20th, 2007 07:48 AM

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

zaghmout July 22nd, 2007 12:28 AM

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"


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

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