Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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
XML
<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>
Posted
Updated 12-Mar-14 12:24pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Mar-14 18:07pm    
It's hard to see what happens when you don't provide any code sample.
—SA

Hi write binding of gridview in one function and call it like
C#
Private void BindNews();
{
 //Binding code
}
protected void grdShowNews_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  grdShowNews.PageIndex = e.NewPageIndex;
  BindNews();
}
 
Share this answer
 
In PageIndexChanging Event,

C#
grdShowNews.PageIndex = e.NewPageIndex;

//Method to Load your GridView

Bind_Grid();
 
Share this answer
 
After clicking the Page Number link, your DataSource
C#
news.ListArchive();
will lose its data, so do like this,


In PageIndexChanging Event,

C#
grdShowNews.PageIndex = e.NewPageIndex;

//Method to Load your GridView

Bind_Grid();
 
Share this answer
 
I've solved this myself! Thanks to all
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900