DropDown List Box
-
Hi, i have three dropdown boxes, in first drop down boxes i have a items of databases name. i want 2nd drop down box contains list of tables dependent on dropdown box1 of databasename. please guide me, 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.DataTextField = "Database_name"; //DropDownList1.DataValueField = "Database_size"; DropDownList1.DataBind(); } thanks, Murugavel
-
Hi, i have three dropdown boxes, in first drop down boxes i have a items of databases name. i want 2nd drop down box contains list of tables dependent on dropdown box1 of databasename. please guide me, 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.DataTextField = "Database_name"; //DropDownList1.DataValueField = "Database_size"; DropDownList1.DataBind(); } thanks, Murugavel
hi murugavel protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds1 = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases1"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds1); DropDownList2.DataSource = ds1; DropDownList2.DataTextField = "Database_Value1"; DropDownList2.DataValueField = "Database_ID1"; DropDownList2.DataBind(); } } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds2 = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases2"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds2); DropDownList3.DataSource = ds2; DropDownList3.DataTextField = "Database_Value2"; DropDownList3.DataValueField = "Database_ID2"; DropDownList3.DataBind(); } } -sathis-
-
hi murugavel protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds1 = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases1"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds1); DropDownList2.DataSource = ds1; DropDownList2.DataTextField = "Database_Value1"; DropDownList2.DataValueField = "Database_ID1"; DropDownList2.DataBind(); } } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { DataSet ds2 = new DataSet(); using (SqlConnection sqlcon = new SqlConnection("Data Source=localhost;Initial Catalog=master;integrated security=true")) { sqlcon.Open(); string sQuery = "exec sp_databases2"; SqlCommand cmd = new SqlCommand(sQuery, sqlcon); SqlDataAdapter objSqlDA = new SqlDataAdapter(cmd); objSqlDA.Fill(ds2); DropDownList3.DataSource = ds2; DropDownList3.DataTextField = "Database_Value2"; DropDownList3.DataValueField = "Database_ID2"; DropDownList3.DataBind(); } } -sathis-
Hi, I think u didnt understand my question. for example. in dropdownlist1 -- i select the northwinddatabase. in dropdownlist2 -- list the table names depend on dropdownlist1 in dropdownlist3 -- list the columns contains in the table depend on dropdownlist2 Thanks, Murugavel
-
Hi, I think u didnt understand my question. for example. in dropdownlist1 -- i select the northwinddatabase. in dropdownlist2 -- list the table names depend on dropdownlist1 in dropdownlist3 -- list the columns contains in the table depend on dropdownlist2 Thanks, Murugavel
Murugavel Sadagopan wrote:
Hi, i have three dropdown boxes, in first drop down boxes i have a items of databases name. i want 2nd drop down box contains list of tables dependent on dropdown box1 of databasename. please guide me,
Where you are mentioned following,In the above question :doh:
Murugavel Sadagopan wrote:
in dropdownlist3 -- list the columns contains in the table depend on dropdownlist2
EVEN THE WORD IMPOSSIBLE SAYS I M POSSIBLE.
modified on Tuesday, July 8, 2008 3:05 AM
-
Hi, I think u didnt understand my question. for example. in dropdownlist1 -- i select the northwinddatabase. in dropdownlist2 -- list the table names depend on dropdownlist1 in dropdownlist3 -- list the columns contains in the table depend on dropdownlist2 Thanks, Murugavel
I would create a class that accepts SqlParameter[] (Array). Than you add the SqlParameter[] as addRange to the SqlConnection Small Example?
SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@databaseID", dropDownList1.SelectedValue); ddlDropDownlist2 = MyClass.FillMyDropDownList(ddlDropDownlist2, parms, "ddlText", "ddlID", "ConnectionString", "SqlCommandOrStoredProcedure"); public DropDownList FillMyDropDown(DropDownList ddlName, SqlParameter[] parms, String TextValue, String IDValue, String ConnectionName, String StoredProcedure) { SqlCommand cmd = null; cmd = BaseDatabaseData(StoredProcedure, parms, ConnectionName); ddlName.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection); ddlName.DataTextField = TextValue; ddlName.DataValueField = IDValue; ddlName.DataBind() cmd.Connection.Close(); return ddlName; } private SqlCommand BaseDatabaseData(String StoredProc, SqlParameter[] arrParameters, String ConnectionName) { try { String connection = System.Configuration.ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString; SqlConnection con = new SqlConnection(connection); SqlCommand cmd = new SqlCommand(StoredProc, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddRange(arrParameters); cmd.CommandTimeout = 3600; cmd.UpdatedRowSource = UpdateRowSource.None; if (cmd.Connection.State.Equals(ConnectionState.Open)) cmd.Connection.Close(); cmd.Connection.Open(); return cmd; } catch (Exception err) { throw new Exception(err.Message, err.InnerException); } }