允许在网格视图中分页 [英] allow paging in the grid view
本文介绍了允许在网格视图中分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在网格视图中进行分页,并通过代码将网格视图绑定为代码
公共 部分 class payment_detail:System.Web.UI.Page
{
SqlConnection con = 新 SqlConnection(ConfigurationManager.ConnectionStrings [" ].ConnectionString);
小数a;
小数b;
小数c;
受保护的 无效 Page_Load(对象发件人,EventArgs e)
{
}
受保护的 无效 Button1_Click(对象发件人,EventArgs e)
{
// SqlDataAdapter da =新SqlDataAdapter(从TRANSACTIONTBL中选择*,其中NAME ='" + DropDownList1.SelectedItem.Text +'和BILLNO ='"+ TextBox1.Text +"',con);
SqlDataAdapter da = 新 SqlDataAdapter(" + DropDownList1.SelectedItem.Text + '",等);
con.Open();
DataSet ds = 新 DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
/// ////////////
con.Open();
// SqlCommand cmd = new SqlCommand(从TRANSACTIONTBL中选择*,其中NAME ='" + DropDownList1.SelectedItem.Text +"'and BILLNO ='"+ TextBox1.Text +"',con);
SqlCommand cmd = 新 SqlCommand(" + DropDownList1.SelectedItem.Text + '",等);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
一个+ = Convert.ToDecimal(dr [" ].ToString());
b + = Convert.ToDecimal(dr [" ].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 ;
}
}
}
我在属性
解决方案
尝试此
受保护的 无效 GridView1_PageIndexChanging(对象发件人,GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; SqlDataAdapter da = 新 SqlDataAdapter(" + DropDownList1.SelectedItem.Text + '",等); con.Open(); DataSet ds = 新 DataSet(); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close(); }
谢谢
Ashish
设置网格属性AllowPaging ="True"和OnPageIndexChanging ="GridView1_PageIndexChanging"
受保护的 无效 GridView1_PageIndexChanging(对象发件人,GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); }
hi
i want paging in my grid view and i bind my grid view by the code the code is
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
解决方案
Try this
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
Set Your Grid Property AllowPaging="True" and OnPageIndexChanging="GridView1_PageIndexChanging"
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); }
这篇关于允许在网格视图中分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文