本文介绍了asp.net中gridview中的分页问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨所有

i在asp.net中有一个gridview,我启用了allow paging,我为事件编写了代码grdShowNews_PageIndexChanging



when我点击gridview底部的页码我点击后页码是不可见的。

感谢所有

对不起,如果我不能写得很好。



PageIndexChanging代码

protected void grdShowNews_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

试试

{

news.IsCounty = IsCounty;

if(IsCounty)grdShowNews.Columns [2] .Visible = true;

grdShowNews.DataSource = news.ListArchive();

grdShowNews.PageIndex = e.NewPageIndex;

grdShowNews.DataBind ();

if(!IsCounty)grdShowNews.Columns [2] .Visible = false;

}

catch(Exception ex)

{

((ASP.tools_popup_ascx)Page.Master.FindControl(Popup))。Show(ex.Message,خطا);

}



}



这是我的gridview

hi to all
i have a gridview in asp.net and i enable allow paging and i write code for event grdShowNews_PageIndexChanging

when i clicked on page number on Bottom of gridview After my click the page numbers is Invisible.
thanks for all
and sorry if i can not write english very well.

PageIndexChanging Code
protected void grdShowNews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
news.IsCounty = IsCounty;
if (IsCounty) grdShowNews.Columns[2].Visible = true;
grdShowNews.DataSource = news.ListArchive();
grdShowNews.PageIndex = e.NewPageIndex;
grdShowNews.DataBind();
if (!IsCounty) grdShowNews.Columns[2].Visible = false;
}
catch (Exception ex)
{
((ASP.tools_popup_ascx)Page.Master.FindControl("Popup")).Show(ex.Message, "خطا");
}

}

and this is my gridview

<asp:GridView ID="grdShowNews" CssClass="grid" runat="server" AutoGenerateColumns="False" RowStyle-Height="30px" HeaderStyle-Height="40px" RowStyle-CssClass="GridRowsStyle" AlternatingRowStyle-CssClass="GridAlternativeRow" HeaderStyle-CssClass="GridHeader" DataKeyNames="ID" Width="100%" OnRowDataBound="grdShowNews_RowDataBound" AllowPaging="True" OnPageIndexChanging="grdShowNews_PageIndexChanging" HorizontalAlign="Center" PageSize="5">
        <AlternatingRowStyle CssClass="GridAlternativeRow" />
        <Columns>
            <asp:TemplateField ControlStyle-Width="100" HeaderText="عنوان" ItemStyle-Width="100px">
                <ItemTemplate>
                    <%# TextTools.GetSubStringText(Eval("Title").ToString(),40) %>
                </ItemTemplate>
                <ControlStyle Width="100px" />
                <ItemStyle Width="100px" />
            </asp:TemplateField>
            <asp:TemplateField ControlStyle-Width="200" HeaderText="متن" ItemStyle-Width="200px">
                <ItemTemplate>
                    <%# TextTools.GetSubStringText(Eval("Text").ToString(),100) %>
                </ItemTemplate>
                <ControlStyle Width="200px" />
                <ItemStyle Width="200px" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="تاریخ">
                <ItemStyle Width="60px" />
                <ItemTemplate>
                    <%#ConvertDate.GetPersianDate((DateTime)Eval("Date")) %>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EditRowStyle Height="80px" />
        <HeaderStyle CssClass="GridHeader" Height="40px" />
        <PagerSettings Mode="NumericFirstLast" />
        <PagerStyle CssClass="pagerStyle" />
        <RowStyle CssClass="GridRowsStyle" Height="60px" />
    </asp:GridView>

推荐答案

Private void BindNews();
{
 //Binding code
}
protected void grdShowNews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  grdShowNews.PageIndex = e.NewPageIndex;
  BindNews();
}


grdShowNews.PageIndex = e.NewPageIndex;

//Method to Load your GridView

Bind_Grid();


news.ListArchive();

会丢失它的数据,所以这样做,





在PageIndexChanging事件中,



will lose its data, so do like this,


In PageIndexChanging Event,

grdShowNews.PageIndex = e.NewPageIndex;

//Method to Load your GridView

Bind_Grid();


这篇关于asp.net中gridview中的分页问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:55