我已经在自己的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();
}
但是在更改页面编号时,它无法正常工作,而是刷新页面。
答案 0 :(得分:1)
首先将var $containers = $('.scrollable');
$containers.each(function() { // in case there are multiple scrollable tables on the page
var $container = $(this);
var $table = $container.find('table');
if ( $container.width() < $table.width() ) {
$container.addClass('show-notice');
}
});
放入.scrollable.show-notice p { display: block; }
Grid
您只需要制作一种填充GridView的方法 像这样
Update Panel
像这样在页面加载上
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
//YourGrid
</ContentTemplate>
</asp:UpdatePanel>
private void populateGrid()
{
//Code For Populating GridView
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populateGrid();
}
}
您已经完成
答案 1 :(得分: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>
答案 2 :(得分: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();
}