Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a DropDownList & a GridView Control in my webform.My requirement is to Select a Database Table Name which were added as Item to DropDownList. When I selectd a Table Name from DropDownList I need the information of that database table name will be displayed on the web page in gridview format.Plz suggest me the code fro above criteria.
Posted

try this on selected index changed event of dropdown list
C#
protected void d_selected_indexchanged(object sender, EventArgs e)
   {
       string str = "Select *from " + DropDownList1.SelectedValue.ToString().Trim() + "";
       SqlCommand cmd = new SqlCommand(str,Db.GetConnection());

       SqlDataAdapter ad = new SqlDataAdapter(cmd);
       DataTable dt = new DataTable();

       ad.Fill(dt);
       GridView1.DataSource = dt;
       GridView1.DataBind();
   }
 
Share this answer
 
ddlUsers_SelectedIndexChanged of Dropdownlist you can get the selected table name & you can bind your Gridview in that event.
 
Share this answer
 
v2
 
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