Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want paging in my grid view and i bind my grid view by the code the code is



C#
public partial class payment_detail : System.Web.UI.Page
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["order"].ConnectionString);
        Decimal a;
           Decimal b;
           Decimal c;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //SqlDataAdapter da=new SqlDataAdapter("select * from TRANSACTIONTBL where NAME='"+DropDownList1.SelectedItem.Text+"' and BILLNO='"+TextBox1.Text+"'",con);
            SqlDataAdapter da = new SqlDataAdapter("select * from TRANSACTIONTBL where NAME='" + DropDownList1.SelectedItem.Text + "'", con);
                con.Open();
                DataSet ds = new DataSet();
                da.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
                con.Close();
            //////////////

                con.Open();

               // SqlCommand cmd = new SqlCommand("select * from TRANSACTIONTBL where NAME='" + DropDownList1.SelectedItem.Text + "' and BILLNO='" + TextBox1.Text + "'", con);
                SqlCommand cmd = new SqlCommand("select * from TRANSACTIONTBL where NAME='" + DropDownList1.SelectedItem.Text + "'", con);
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    a += Convert.ToDecimal(dr["DEBIT"].ToString());
                    b += Convert.ToDecimal(dr["CREDIT"].ToString());
                }
                c = b - a;
                Label1.Text = a.ToString();
                Label2.Text = b.ToString();
                Label3.Text = c.ToString();
                Label4.Visible = true;
                Label5.Visible = true;
                Label6.Visible = true; 
        }
      
    }
}


i change the allow paging to true in the properties
Posted
Updated 28-Jul-12 0:19am
v2

Try this

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
SqlDataAdapter da = new SqlDataAdapter("select * from TRANSACTIONTBL where NAME='" + DropDownList1.SelectedItem.Text + "'", con);
                con.Open();
                DataSet ds = new DataSet();
                da.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
                con.Close();
    }

Thanks
Ashish
 
Share this answer
 
Comments
[no name] 28-Jul-12 6:30am    
my 5+++
Rahul Rajat Singh 31-Jul-12 23:56pm    
good answer. +5.
Set Your Grid Property AllowPaging="True" and OnPageIndexChanging="GridView1_PageIndexChanging"

C#
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
 
Share this answer
 
Comments
[no name] 28-Jul-12 6:30am    
my 5+++++

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