Click here to Skip to main content
15,921,467 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted

Fetch all the tables into a DataSet and then change the datasource property of grid view correspondingly.
 
Share this answer
 
Comments
10923679 19-Aug-14 1:17am    
can u pls help me with few code.. and steps
Thanks7872 19-Aug-14 1:30am    
Why? Use your favorite search engine and you will be able to do it. Its not that hard.
10923679 19-Aug-14 2:00am    
yeah right ... its nt that hard..
i found the solution..
can u tell me how to fix the length of gridview
if more no. of records is also there . it shoudnt expand
OK. Try doint something like this.

C#
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];
}
 
Share this answer
 
Comments
10923679 19-Aug-14 1:56am    
thanks dude for ur help
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;
}
}
}
 
Share this answer
 

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