同时改变页面没有从寻呼gridview的网页获得刷新

问题描述 投票:1回答:3

我已经实现了我的GridView中paging功能。下面是代码

<asp:GridView ID="grdCMPChangeDetails" runat="server" CssClass="table table-bordered" AutoGenerateColumns="false" AllowPaging="true" PageSize="1" PageIndex="1"
                                        OnPageIndexChanging="grdCMPChangeDetails_PageIndexChanging">
                                        <Columns>
                                            <asp:BoundField ItemStyle-Width="150px" DataField="SAP-ID" HeaderText="SAP ID" />
                                            <asp:BoundField ItemStyle-Width="150px" DataField="LAT" HeaderText="Latitude" />
                                            <asp:BoundField ItemStyle-Width="150px" DataField="LONG" HeaderText="Longitude" />
                                            <asp:BoundField ItemStyle-Width="150px" DataField="R4GSTATE" HeaderText="State" />
                                            <asp:BoundField ItemStyle-Width="150px" DataField="OLD_LATITUDE" HeaderText="Old Latitude" />
                                            <asp:BoundField ItemStyle-Width="150px" DataField="OLD_LONGITUDE" HeaderText="Old Longitude" />
                                        </Columns>
                                    </asp:GridView>

CS

Datatbind

grdCMPChangeDetails.DataSource = dtSuccessRecord;
                    grdCMPChangeDetails.DataBind();

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

但同时不改变页面,它没有工作,而不是页面越来越刷新。

c# asp.net gridview paging
3个回答
1
投票

首先进行的GridUpdate Panel

<asp:UpdatePanel ID="updatePanel" runat="server">
   <ContentTemplate>
       //YourGrid
   </ContentTemplate>
</asp:UpdatePanel>

你只需要做出一种用于填充的GridView这样

private void populateGrid()
{
   //Code For Populating GridView
}

把它放在页面加载像这样

protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {                
                populateGrid();
            }
        }

on Page Index这样

   protected void grdCMPChangeDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            try
            {
                grdCMPChangeDetails.PageIndex = e.NewPageIndex;
                populateGrid();              
            }
            catch (Exception ex)
            {

            }
        }

大功告成


0
投票

我认为你需要把你的网格视图到一个更新面板,以避免您的问题:

<asp:UpdatePanel ID="myUpdPanel" runat="server" UpdateMode="Conditional">
   <asp:GridView ID="grdCMPChangeDetails" runat="server" CssClass="table table-bordered" 
    AutoGenerateColumns="false" AllowPaging="true" PageSize="1" PageIndex="1"                                       
    OnPageIndexChanging="grdCMPChangeDetails_PageIndexChanging">
   <Columns>
      <asp:BoundField ItemStyle-Width="150px" DataField="SAP-ID" HeaderText="SAP ID" />
      <asp:BoundField ItemStyle-Width="150px" DataField="LAT" HeaderText="Latitude" />
      <asp:BoundField ItemStyle-Width="150px" DataField="LONG" HeaderText="Longitude" />
      <asp:BoundField ItemStyle-Width="150px" DataField="R4GSTATE" HeaderText="State" />
      <asp:BoundField ItemStyle-Width="150px" DataField="OLD_LATITUDE" HeaderText="Old Latitude" />
      <asp:BoundField ItemStyle-Width="150px" DataField="OLD_LONGITUDE" HeaderText="Old Longitude" />
   </Columns>
   </asp:GridView>
</asp:UpdatePanel>

0
投票

什么我能看到的是你在呼唤电网控制的DataBind方法。您必须填充变化经历完全结合的过程。取而代之的是,你的PageIndexChanging事件改成这样:

protected void grdCMPChangeDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    grdCMPChangeDetails.PageIndex = e.NewPageIndex;
    // Fetch your results from db again or save your search results in ViewState so that you are not hitting the database again and again
    var dtSuccessRecord = SomeDatabaseCall(); 
    // Attach it to the Grid Control again and then head towards binding it.
    grdCMPChangeDetails.DataSource = dtSuccessRecord;
    grdCMPChangeDetails.DataBind();
}
© www.soinside.com 2019 - 2024. All rights reserved.