The Question is the programmer has to design a page as shown below.
Before the web page is loaded the programmer has to load all the table names from Database(he specifies in web.config file). the user can select any item from the dropdown list then the selected item( table name).then we need to display entire details in that table using gridview.
Krishna GaradPosted Jan 18, 2012, 5:19 AM
Page_Load
{
SqlConnection Cn=new SqlConnection("ConnectionstringHere");
SqlCommand cmd=new SqlCommand("
SELECT * FROM sys.Tables",cn);SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
DropDownList1.DataSource=ds.Tables[0];
DropDownList1.DataTextField="name";
DropDownList1.DataValueField="name";
DropDownList1.DataBind();
}
and in dropdownlist selected index changed event you can select records from the selected table in dropdownlist.
Naga KotaPosted Jan 23, 2012, 2:10 AM
Krishna GaradPosted Jan 18, 2012, 7:09 AM
DropDownList1_SelectedIndexChanged
{
SqlConnection Cn=new SqlConnection("ConnectionstringHere");
SqlCommand cmd=new SqlCommand("
SELECT * FROM "+DropDownList1.SelectedValue.ToString(),cn);SqlDataAdapter da=new SqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
}
Naga KotaPosted Jan 18, 2012, 6:32 AM
can u tell
=>how can i retrieve entire data into grid view of selected list item.
Jignesh TrivediPosted Jan 18, 2012, 5:08 AM
you may retreive your table name from avalable in DB. here queryfor this.
select * from sys.objects s where type='U'
and how to create connection
using System.Data.SqlClient;
SqlConnection myConnection = new SqlConnection("user id=username;password=password;server=serverurl;Trusted_Connection=yes;database=database; connection timeout=30");
myConnection.Open();
DataSet dset = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("select * from sys.objects s where type='U'", myConnection);
adp.Fill(dset);
ComboBox1.DataSource = dset.Tables(00;
ComboBox1.DisplayMember = "Name";
myConnection.Close()
hope this help.
Naga KotaPosted Jan 18, 2012, 4:01 AM
the list items in drop down list is the names of tables available in database(given by user).There we need to bind the dropdown list.
when user selects a list item from drop down list then we need to entire data of that particular table.
can i know how to bind the dropdown list by writing code.
Naga KotaPosted Jan 18, 2012, 3:56 AM
Jignesh TrivediPosted Jan 18, 2012, 3:54 AM
from your blog i not getting you. canu please provide more details.
Datta KharadPosted Jan 18, 2012, 3:49 AM
Programmer has to design a page as user can select any item from the dropdown list then the selected item table is to shown to user.