如何使用不同的按钮在Griedview中绑定多个表... [英] How Do I Bind Multiple Tables In A Griedview Using Different Buttons...
本文介绍了如何使用不同的按钮在Griedview中绑定多个表...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GRIDVIEW(记录不断变化)
......................... ...............
btn1(button1)注意:如果button1点击table1将显示在gridview
btn2(button2)注意:如果button2点击table2将在gridview中显示
bnn3( button3)注意:如果button3点击table3将在gridview中显示
解决方案
将所有表提取到DataSet中,然后相应地更改网格视图的datasource属性。
确定。尝试这样的事情。
受保护 void Button1_Click( object sender,EventArgs e)
{
gridView1.DataSource = ds.Tables [< span class =code-digit> 0 ];
}
受保护 void Button2_Click( object sender,EventArgs e)
{
gridView1.DataSource = ds.Tables [ 1 ];
}
受保护 void Button1_Click( object sender,EventArgs e)
{
gridView1.DataSource = ds.Tables [ 2 ];
}
使用System.Data.SqlClient;
使用System.Data;
$ / b
公共部分类_Default:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
}
string con_str = @Data Source = ABC; Initial Catalog = DBname; Integrated Security = True;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(con_str);
SqlDataAdapter ad1;
DataSet ds = new DataSet();
ad1 = new SqlDataAdapter(select * from table1,con);
ad1.Fill(ds,0);
GridView1.DataSource = ds.Tables [0];
GridView1.DataBind();
GridView1 .Visible = true;
}
protected void Button2_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(con_str);
SqlDataAdapter ad1;
DataSet ds = new DataSet();
ad1 = new SqlDataAdapter(select * from table2,con);
ad1.Fill(ds,1);
GridView1.DataSource = ds.Tables [1];
GridView1.DataBind();
GridView1.Visible = true;
}
}
}
GRIDVIEW(records keep on changing )
.......................................
btn1(button1)note: if button1 clicked table1 will show in gridview
btn2(button2)note: if button2 clicked table2 will show in gridview
btn3 (button3)note: if button3 clicked table3 will show in gridview
解决方案
Fetch all the tables into a DataSet and then change the datasource property of grid view correspondingly.
OK. Try doint something like this.
protected void Button1_Click(object sender, EventArgs e) { gridView1.DataSource = ds.Tables[0]; } protected void Button2_Click(object sender, EventArgs e) { gridView1.DataSource = ds.Tables[1]; } protected void Button1_Click(object sender, EventArgs e) { gridView1.DataSource = ds.Tables[2]; }
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
string con_str = @"Data Source=ABC;Initial Catalog=DBname;Integrated Security=True";
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(con_str);
SqlDataAdapter ad1;
DataSet ds = new DataSet();
ad1 = new SqlDataAdapter("select * from table1", con);
ad1.Fill(ds, "0");
GridView1.DataSource = ds.Tables["0"];
GridView1.DataBind();
GridView1.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(con_str);
SqlDataAdapter ad1;
DataSet ds = new DataSet();
ad1 = new SqlDataAdapter("select * from table2", con);
ad1.Fill(ds, "1");
GridView1.DataSource = ds.Tables["1"];
GridView1.DataBind();
GridView1.Visible = true;
}
}
}
这篇关于如何使用不同的按钮在Griedview中绑定多个表...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文