Amit Kumar

Amit Kumar

  • NA
  • 140
  • 40.9k

PageIndexChanging not working in Gridview

Aug 17 2013 8:01 AM
I have gridview 


 <asp:GridView ID="gvArticles" runat="server" DataKeyNames="ArticleID" 
        HeaderStyle-BackColor="#87cfe6" AutoGenerateColumns="false" ForeColor="White" 
        AllowPaging="true" AllowSorting="true" PageSize="3" Width="100%">
        <Columns>
    <asp:TemplateField>
    <ItemTemplate>
        <asp:ImageButton ID="imgDel" runat="server" CommandName="Delete" ImageUrl="~/Images/delete.jpg" Width="20px" Height="20px"/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Title">
    <ItemTemplate>
        <asp:Label ID="lblTitle" runat="server" Text='<%#Eval("Title")%>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Added Date">
    <ItemTemplate>
        <asp:Label ID="lblDate" runat="server" Text='<%#Eval("AddedDate") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

and this is the code for .cs file 


public partial class DeleteArticles : System.Web.UI.Page
{
    string str = ConfigurationManager.ConnectionStrings["connect"].ConnectionString;
    SqlConnection con;
    SqlCommand cmd;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gvArt();
        }
    }
    protected void gvArt()
    {
        con = new SqlConnection(str);
        con.Open();
        cmd = new SqlCommand("select * from Articles",con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        gvArticles.DataSource = ds;
        gvArticles.DataBind();
        con.Close();
    }
    protected void gvArticles_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
       
    }
}


but when i try to change pageindex it doesn't change .

Answers (3)