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. about dropdownlist

about dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasewpfwcftutorialannouncement
14 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.
  • R Offline
    R Offline
    Rajeshwar Code Developer
    wrote on last edited by
    #1

    hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

    try and try untill reach success..

    A S A 3 Replies Last reply
    0
    • R Rajeshwar Code Developer

      hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

      try and try untill reach success..

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Rajeshwar Code- Developer wrote:

      so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

      If you have the user information, its means you know the User Country. So set the Same to ddlCountry.

      DropDownList1.SelectedValue = UserCountry;

      Hope this will help :-D

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

      R 1 Reply Last reply
      0
      • A Abhijit Jana

        Rajeshwar Code- Developer wrote:

        so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

        If you have the user information, its means you know the User Country. So set the Same to ddlCountry.

        DropDownList1.SelectedValue = UserCountry;

        Hope this will help :-D

        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

        R Offline
        R Offline
        Rajeshwar Code Developer
        wrote on last edited by
        #3

        thanks for reply i tried that .. seletedvalue showing null value..

        try and try untill reach success..

        A 1 Reply Last reply
        0
        • R Rajeshwar Code Developer

          thanks for reply i tried that .. seletedvalue showing null value..

          try and try untill reach success..

          A Offline
          A Offline
          Abhijit Jana
          wrote on last edited by
          #4

          Rajeshwar Code- Developer wrote:

          i tried that .. seletedvalue showing null value..

          Why does you DropDown list does not have any data ? What are the value of those ?

          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

          R 1 Reply Last reply
          0
          • A Abhijit Jana

            Rajeshwar Code- Developer wrote:

            i tried that .. seletedvalue showing null value..

            Why does you DropDown list does not have any data ? What are the value of those ?

            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

            R Offline
            R Offline
            Rajeshwar Code Developer
            wrote on last edited by
            #5

            here the thing is i was many countries binding to ddl frm countries table .. so there is one more table called userdetails. for one user having one country right .. i want show automatically his country inj ddl.

            try and try untill reach success..

            A 1 Reply Last reply
            0
            • R Rajeshwar Code Developer

              here the thing is i was many countries binding to ddl frm countries table .. so there is one more table called userdetails. for one user having one country right .. i want show automatically his country inj ddl.

              try and try untill reach success..

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              This is my Dropdownlist. [ I assume you are binding it from Database.

              us
              india
              koria
              canada

              [ I have removed / for formatting. ] In page load I am using this,

              protected void Page_Load(object sender, EventArgs e)
              {
              DropDownList1.SelectedValue = "india";
              }

              Here rather than india, you should use the value of user country.

              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

              R 1 Reply Last reply
              0
              • A Abhijit Jana

                This is my Dropdownlist. [ I assume you are binding it from Database.

                us
                india
                koria
                canada

                [ I have removed / for formatting. ] In page load I am using this,

                protected void Page_Load(object sender, EventArgs e)
                {
                DropDownList1.SelectedValue = "india";
                }

                Here rather than india, you should use the value of user country.

                Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                R Offline
                R Offline
                Rajeshwar Code Developer
                wrote on last edited by
                #7

                thanks abhijith !!! See my code one.. ddlCountry.SelectedValue = ds.Tables[0].Rows[0]["sCountry"].ToString(); am doing like this ? in Selectedvalue showing null value.

                try and try untill reach success..

                1 Reply Last reply
                0
                • R Rajeshwar Code Developer

                  hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

                  try and try untill reach success..

                  S Offline
                  S Offline
                  Suresh Suthar
                  wrote on last edited by
                  #8

                  Rajeshwar First bind the ddlCountry with your country table data and than use below mentioned code to select user's country.

                  ddlCountry.ClearSelection()
                  ddlCountry.Items.FindByText("user's country").Selected = True

                  Be an Eagle, Sky is Yours.

                  R 1 Reply Last reply
                  0
                  • S Suresh Suthar

                    Rajeshwar First bind the ddlCountry with your country table data and than use below mentioned code to select user's country.

                    ddlCountry.ClearSelection()
                    ddlCountry.Items.FindByText("user's country").Selected = True

                    Be an Eagle, Sky is Yours.

                    R Offline
                    R Offline
                    Rajeshwar Code Developer
                    wrote on last edited by
                    #9

                    still there is no result..

                    try and try untill reach success..

                    1 Reply Last reply
                    0
                    • R Rajeshwar Code Developer

                      hi!!!! i need to know .. i have one dropdownlist called as ddlcountry. in this ddlcountry i m binding with table name called countries . i have one more table called userdetails .. already one user registered and selected his country frm ddl called USA . so my doubt is i want to update his profile . when even user click his update page so i ll all from of him form db , here in ddlcountry .automatically show USA in ddlcoutry, do u know how to do it.

                      try and try untill reach success..

                      A Offline
                      A Offline
                      Abhishek Sur
                      wrote on last edited by
                      #10

                      When page loads, first Bind the Data with the dllCountry. Choose appropriate DataTextField and DataValueField. Now after you finish your load using DataBind, use this.dllCountry.SelectedValue with the DataValueField you want. Also please check if you have wrote If(IsPostBack)return; in the Form_Load, so that when the page is posted back the selection remains. :thumbsup:

                      Abhishek Sur


                      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                      **Don't forget to click "Good Answer" if you like to.

                      A 1 Reply Last reply
                      0
                      • A Abhishek Sur

                        When page loads, first Bind the Data with the dllCountry. Choose appropriate DataTextField and DataValueField. Now after you finish your load using DataBind, use this.dllCountry.SelectedValue with the DataValueField you want. Also please check if you have wrote If(IsPostBack)return; in the Form_Load, so that when the page is posted back the selection remains. :thumbsup:

                        Abhishek Sur


                        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                        **Don't forget to click "Good Answer" if you like to.

                        A Offline
                        A Offline
                        Abhijit Jana
                        wrote on last edited by
                        #11

                        Abhishek Sur wrote:

                        Choose appropriate DataTextField and DataValueField.

                        I guess he is missing bind with DataValueField :)

                        Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                        A R 2 Replies Last reply
                        0
                        • A Abhijit Jana

                          Abhishek Sur wrote:

                          Choose appropriate DataTextField and DataValueField.

                          I guess he is missing bind with DataValueField :)

                          Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                          A Offline
                          A Offline
                          Abhishek Sur
                          wrote on last edited by
                          #12

                          yes... right. If DataValueField is not specified, the value will be same as DataTextField. I personally always set ID as value so that I could set SelectedValue with some numeric field or GUID, as TextField may repeat. :rose:

                          Abhishek Sur


                          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

                          **Don't forget to click "Good Answer" if you like to.

                          1 Reply Last reply
                          0
                          • A Abhijit Jana

                            Abhishek Sur wrote:

                            Choose appropriate DataTextField and DataValueField.

                            I guess he is missing bind with DataValueField :)

                            Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                            R Offline
                            R Offline
                            Rajeshwar Code Developer
                            wrote on last edited by
                            #13

                            thnks for all who reply me .. i tried like this also bu there is no output.. and this is my code if (!IsPostBack) { DataSet ds1 = new DataSet(); ds1 = ad.dsGetvalues("Select * from Countries", true); ddlCountry.DataSource = ds1; ddlCountry.DataTextField = "sCountryName"; ddlCountry.DataValueField = "sno"; ddlCountry.Items.Insert(0, "--Select--"); ddlCountry.DataBind(); DataSet dss = new DataSet(); dss = ad.dsGetvalues("select * from UserDetails where PkiUsername ='"+Session["Username"].ToString()+"' ", true); ddlCountry.SelectedValue = dss.Tables[0].Rows[0]["sCountry"].ToString(); }

                            try and try untill reach success..

                            A 1 Reply Last reply
                            0
                            • R Rajeshwar Code Developer

                              thnks for all who reply me .. i tried like this also bu there is no output.. and this is my code if (!IsPostBack) { DataSet ds1 = new DataSet(); ds1 = ad.dsGetvalues("Select * from Countries", true); ddlCountry.DataSource = ds1; ddlCountry.DataTextField = "sCountryName"; ddlCountry.DataValueField = "sno"; ddlCountry.Items.Insert(0, "--Select--"); ddlCountry.DataBind(); DataSet dss = new DataSet(); dss = ad.dsGetvalues("select * from UserDetails where PkiUsername ='"+Session["Username"].ToString()+"' ", true); ddlCountry.SelectedValue = dss.Tables[0].Rows[0]["sCountry"].ToString(); }

                              try and try untill reach success..

                              A Offline
                              A Offline
                              Abhijit Jana
                              wrote on last edited by
                              #14

                              Rajeshwar Code- Developer wrote:

                              ddlCountry.DataValueField = "sno";

                              Try this

                              ddlCountry.DataTextField = "sCountryName";
                              ddlCountry.DataValueField = "sCountryName";

                              Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article

                              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