DropDown ADD items
-
Hi, In Visual studio 2005, i have a drop down list. i want to add list of databases in dropdown list. i try the below mentioned code. But it returns System.Data.DataRowView in dropdown list not the database name. I also ensure in SQL Server execute the command "exec sp_databases" it returns 16 Databases names and autopostback property is also true. protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds); DropDownList1.DataSource = ds; DropDownList1.DataBind(); } Thanks, Murugavel
-
Hi, In Visual studio 2005, i have a drop down list. i want to add list of databases in dropdown list. i try the below mentioned code. But it returns System.Data.DataRowView in dropdown list not the database name. I also ensure in SQL Server execute the command "exec sp_databases" it returns 16 Databases names and autopostback property is also true. protected void Page_Load(object sender, EventArgs e) { DataSet ds = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds); DropDownList1.DataSource = ds; DropDownList1.DataBind(); } Thanks, Murugavel
hi U didn't bind the DataTextField and DataValueField of the Dropdownlist. Bind the DataTextField with Database Name and DatavalueField with DatabaseID. Hope this will help u Regards Avesh Agarwal