Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DropDown List Box

DropDown List Box

Scheduled Pinned Locked Moved ASP.NET
sharepointdatabasesecuritytutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Murugavel Sadagopan
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • M Murugavel Sadagopan

      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

      A Offline
      A Offline
      amal_sathis
      wrote on last edited by
      #2

      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-

      M 1 Reply Last reply
      0
      • A amal_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-

        M Offline
        M Offline
        Murugavel Sadagopan
        wrote on last edited by
        #3

        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

        S H 2 Replies Last reply
        0
        • M Murugavel Sadagopan

          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

          S Offline
          S Offline
          Sherin Iranimose
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • M Murugavel Sadagopan

            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

            H Offline
            H Offline
            Herman T Instance
            wrote on last edited by
            #5

            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);
            			}
            		}
            
            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups