Divin Mfwamba

Divin Mfwamba

  • 1.9k
  • 22
  • 9k

without paging my gridview

Jul 23 2013 5:28 AM

Hi!

These codes work without problem.
But in my .aspx file I put this code to paging my gridview. Unfortunatly, nothing happen. Sound like nothing is wrong there:
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4"  FirstPageText="First" LastPageText="Last"/>



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Paging" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:GridView id="GridView2" runat="server"></asp:GridView>            

     <!-- from here-->   
    <PagerSettings Mode="NumericFirstLast" PageButtonCount="4"  FirstPageText="First" LastPageText="Last"/>
    </div>
    </form>
</body>
</html>

///////////////////

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class Paging : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        BindData();
    }

    protected void BindData()
    {
        string strConnection = "Data Source=localhost\\sqlexpress;Initial Catalog=Divin;Integrated Security=True";
        SqlConnection con = new SqlConnection(strConnection);
        SqlCommand cmd = new SqlCommand("select * from userinfo", con);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.DataBind();
        con.Close();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView2.PageIndex = e.NewPageIndex;
        BindData();
    }

}


Answers (6)