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. data binding in dropdown list

data binding in dropdown list

Scheduled Pinned Locked Moved ASP.NET
databasewpfwcf
7 Posts 5 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.
  • S Offline
    S Offline
    smitab
    wrote on last edited by
    #1

    hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006

    M E H S 4 Replies Last reply
    0
    • S smitab

      hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, Your sample code is not correct, you can read the documentation in MSDN to see how to bind a datasource to a control: Data Binding Multi-Record Web Server Controls[^]

      1 Reply Last reply
      0
      • S smitab

        hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006

        E Offline
        E Offline
        enjoycrack
        wrote on last edited by
        #3

        just make sure something: - Why do you put the code of data binding in While loop? - Make sure DataTextField and DataValueFied are correct and the datareader has content... << >>

        S 1 Reply Last reply
        0
        • E enjoycrack

          just make sure something: - Why do you put the code of data binding in While loop? - Make sure DataTextField and DataValueFied are correct and the datareader has content... << >>

          S Offline
          S Offline
          smitab
          wrote on last edited by
          #4

          hi, actually i had done some correction in that code but still its not runing on dat perticular page but its runin on another page why this is happening? sam.

          E 1 Reply Last reply
          0
          • S smitab

            hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006

            H Offline
            H Offline
            HimaBindu Vejella
            wrote on last edited by
            #5

            U are binding ListSelUser.DataTextField = dr.GetString(1); But actually in the ist column of ur data reader there is nothing that is the reason u r ddl is not binding Just replace it with ListSelUser.DataTextField = dr.GetString(0); Remove these two lines of code string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; "I find that the harder I work, the more luck I seem to have."

            1 Reply Last reply
            0
            • S smitab

              hi, actually i had done some correction in that code but still its not runing on dat perticular page but its runin on another page why this is happening? sam.

              E Offline
              E Offline
              enjoycrack
              wrote on last edited by
              #6

              if so, the only way you have to debug line by line to see what is not correct... << >>

              1 Reply Last reply
              0
              • S smitab

                hi all, i m usin dropdown list. i want to access DB field. i have written folling code.... private void Page_Load(object sender, System.EventArgs e) { SqlConnection conn; SqlCommand cmd; SqlDataReader dr; conn= new SqlConnection(ConfigurationSettings.AppSettings["strConn"]); cmd=new SqlCommand(); conn.Open(); cmd.CommandText="select username from user_master"; cmd.Connection=conn; dr=cmd.ExecuteReader(); while(dr.Read()) { ListSelUser.DataSource =dr; ListSelUser.DataTextField = dr.GetString(1); ListSelUser.DataValueField = dr.GetString(0); ListSelUser.DataBind(); conn.Close(); ListSelUser.Items.Insert(0, "mipl"); string itemText = ListSelUser.SelectedItem.Text; string itemValue = ListSelUser.SelectedItem.Value; } } but its showin nothing -- modified at 1:00 Friday 17th March, 2006

                S Offline
                S Offline
                ssoffline
                wrote on last edited by
                #7

                may is ask u one thing , hw can u call getstring(0) and getstring(1) wen y re fetching jus one feild frm the database, check it out again sameer :-O

                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