0

我有一个需要分页的gridview。当我allowPaging = true时,它显示145678910 ....它不会显示第2页和第3页。如果我尝试将模式更改为NextPreviousFirstLast,它只会在第一页显示“Next”,如果我点击它,它只在第二页显示“第一”和“最后”。这是代码:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="Black" AutoGenerateColumns="False" BackColor="#CCCCCC" 
            BorderColor="#666666"    OnRowDataBound  = "HandleRowDataBound" BorderStyle="Solid" BorderWidth="1px" CellSpacing="2" Width ="942px"
            Font-Names="Arial" Font-Size="8pt" ShowHeaderWhenEmpty="True"  CSSClass="mytable" AllowPaging="true" OnPageIndexChanging="GridView1_PageIndexChanging" 
             PageSize="25">
                <PagerSettings  Mode="NextPreviousFirstLast" FirstPageText="First" PreviousPageText="Previous" NextPageText="Next" LastPageText="Last" />
                <Columns>
                    <asp:TemplateField HeaderText="Select" ControlStyle-Width = "30px">
                        <ItemTemplate>
                              <asp:CheckBox runat="server" ID="DiscontinuedCheckBox" CssClass="SelectCheckBox" />
                        </ItemTemplate>
                        <ControlStyle Width="30px"></ControlStyle>
                        <ItemStyle Wrap="False" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Recall Qty"  ItemStyle-Wrap="true"  ItemStyle-Width="100px"   >
                        <ItemTemplate >
                            <img id="star1" runat ="server" src="../Images/red_star.gif" alt="Red Star" class="RedStars"/>
                            <asp:TextBox runat ="server" ID="textBoxQty" Width = "50px"  Text ="1" ReadOnly="false" />
                        </ItemTemplate>
                        <HeaderStyle Width = "100px" />
                        <ItemStyle Width="100px" />
                        <ItemStyle Wrap="False" Width="60px"></ItemStyle>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Delivery Location"     >
                        <ItemTemplate >
                            <div style="width:200px">
                                <div style ="float : left; ">
                                    <asp:CheckBox runat="server" ID="packShipCB" Text ="Pack Ship &nbsp;&nbsp;&nbsp; or " CssClass="SendToShip"  AutoPostBack="false" />
                                </div> 
                                <asp:TextBox runat ="server" ID="deliveryLocationTB"  CssClass="AllDelivery"  ReadOnly ="false" Width="80px"   />
                            </div>
                        </ItemTemplate>
                        <HeaderStyle Width = "200px" />
                        <ItemStyle Width="200px" />
                        <ItemStyle Width ="160px" />
                    </asp:TemplateField>

                    <%-- <asp:BoundField  HeaderText="Data"  />--%>
                    <asp:BoundField HeaderText="Request Number"  DataField="requestNumber"  ItemStyle-Width = "50px">
                        <HeaderStyle Wrap="True" Width="50px" />
                        <ItemStyle Wrap="True" Width="50px" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Item Number"  DataField="materialLineItemID"  />
                    <asp:BoundField HeaderText="Program" DataField="programName" >
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Program POC" DataField="programPOC" >
                        <ItemStyle Wrap="False" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Material Number" DataField="materialNumber" ItemStyle-Width="100px">
                        <HeaderStyle Wrap="False" />
                    </asp:BoundField >
                    <asp:BoundField HeaderText="Qty in Storage" DataField="availableQty" ItemStyle-Width="100px">
                        <ItemStyle Width="100px" Wrap="False"></ItemStyle>
                    </asp:BoundField >
                    <asp:BoundField HeaderText="Description" DataField="Description" ItemStyle-Width="300px" >
                        <ItemStyle Width="300px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Serialized" DataField="Serialized" ItemStyle-Width="100px">
                        <ItemStyle Width="100px"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Serial Number" DataField="serialNumber" ItemStyle-Width="200px">
                        <ItemStyle Width="200px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Shelf Life" DataField="shelfLIfe" DataFormatString="{0:d}" HtmlEncode="false" ItemStyle-Width="100px" >
                        <ItemStyle Width="100px"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Cost Center" DataField="costCenter" ItemStyle-Width="200px">
                        <ItemStyle Width="200px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Charge Number" DataField="chargeNumber" ItemStyle-Width="200px">
                        <ItemStyle Width="200px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField DataField="contractNumber" HeaderText="Contract Number" ItemStyle-Width="200px">
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Width="200px" />
                    </asp:BoundField>

                    <asp:BoundField DataField="assetTagNumber" HeaderText="Asset Tag Number" ItemStyle-Width="200px">
                        <HeaderStyle Wrap="False" />
                        <ItemStyle Width="200px" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Storage Duration" DataField="Duration" ItemStyle-Width="200px">
                        <ItemStyle Width="200px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                    <asp:BoundField HeaderText="Handling Unit Number" DataField="handlingUnitNumber" ItemStyle-Width="100px">
                        <ItemStyle Width="100px" Wrap="False"></ItemStyle>
                    </asp:BoundField >
                    <asp:BoundField HeaderText="Storage Location" DataField="storageLocation" ItemStyle-Width="100px">
                        <ItemStyle Width="100px" Wrap="False"></ItemStyle>
                    </asp:BoundField >
                    <asp:BoundField HeaderText="Time in Storage" DataField="storageTime" ItemStyle-Width="200px">
                        <ItemStyle Width="200px" Wrap="False"></ItemStyle>
                    </asp:BoundField>
                </Columns>
            <FooterStyle BackColor="#CCCCCC" />
            <HeaderStyle  BackColor="#999999" Font-Bold="True" ForeColor="#880C1B" 
                HorizontalAlign="Center" Font-Size="9pt" Wrap="true" BorderStyle="Solid"  VerticalAlign="Middle"
                BorderWidth="1px"/>
            <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left"  />
            <RowStyle BackColor="White" HorizontalAlign="Center" CssClass="Unselected" 
                Wrap="false" />
            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#808080" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#383838" />
        </asp:GridView>

这是背后的代码:

protected void Page_Load(object sender, EventArgs e)
    {

        siteID = int.Parse(Request.QueryString["s"].ToString());
        FillDetails(); 
    }

    //Pulls data from database for items to be recalled based on site, and user rights and enables to functions of the controls 
    private void FillDetails()
    {
        DataSet materials = RequestDB2.GetStoredMaterialsView(siteID);

        GridView1.DataSource = materials;
        GridView1.DataBind();

        if (GridView1.Rows.Count >= 9) 
            paneling.Style["height"] = "300px";
        //if not items exit
        if (materials == null || materials.Tables[0].Rows.Count == 0)
        {
            Error.InnerText = "You have no materials to be recalled from this site.";
        }
        else
        {
            //Adds thead and tbody tags
            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }


    protected void HandleRowDataBound(object sender, GridViewRowEventArgs e)
    {

    }

这是我看到的:在此处输入图像描述

当我查看萤火虫时,我看到第 2 页和第 3 页有显示:无。关于为什么会发生这种情况的任何想法?

4

2 回答 2

1

尝试使用 PagerSetting 作为..

   <PagerSettings  FirstPageText="First Page"  LastPageText="Last Page" 
                   Mode="NumericFirstLast" Position="TopAndBottom" />  

protected void grdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.DataSource  = RequestDB2.GetStoredMaterialsView(siteID);
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}
于 2012-10-25T16:15:32.403 回答
1

您没有在 GridView1_PageIndexChanging 中分配数据源。您需要在绑定之前分配数据源。你最好尝试调用 FillDetails() 更改

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    FillDetails();       
}
于 2012-10-25T16:07:05.370 回答