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. Can i add the database item to drop down list

Can i add the database item to drop down list

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasehelpannouncement
9 Posts 6 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
    sandeep sangshetty
    wrote on last edited by
    #1

    Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

    A I A S C 5 Replies Last reply
    0
    • S sandeep sangshetty

      Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

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

      sandeep sangshetty wrote:

      i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database.

      did you complete the first level, that City and Country read from Database and bind it to dropdown list ? if yes then do one thing, on selectetd index changed of City name ,call the same function that you have used for load country name first time. just change the query as , Select Country from mydB where City='"+ ddlCity.text + "' hope this will help you. if you have any doubts you can ask me .

      cheers, Abhijit

      1 Reply Last reply
      0
      • S sandeep sangshetty

        Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

        I Offline
        I Offline
        Imran Khan Pathan
        wrote on last edited by
        #3

        sandeep sangshetty wrote:

        Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list).

        Yes.DropDownList has SelectedValue property, ddl.SelectedValue="Ahmedabad"; // if value is cityname OR ddl.SelectedValue="YourCityID"; //if value if cityID

        please don't forget to vote on the post that helped you.

        1 Reply Last reply
        0
        • S sandeep sangshetty

          Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

          A Offline
          A Offline
          Anand Desai
          wrote on last edited by
          #4

          Have you filled the Country DDl first in Update Form?? Then do following: 1. Run a query and get CountryID or CountryName What ever you want from Database for that perticular user. (Lets Take ID in this case) 2. write this code after getting CountryID:

          int intCountryID = .....; // ID u got from database
          for(int i=0;i<(ddlCountry.Length);i++)
          {
          if(ddlCountry[i].Value == intCountryID)
          ddlCountry.SelectedIndex = i;
          }

          3. Write this code into ddlCountry's SelectedIndexChanged property:

          .
          .
          .//write code to get cities for that country selected from database
          . here and load all cities into ddlCity
          .
          int intCityID = .....; // ID u got from database
          for(int j=0;j<ddlcity.length);j++)>
          {
          if(ddlCity[i].Value == intCityID )
          ddlCity.SelectedIndex = j;
          }

          4. Bingo!!! Problem Solved Got it?????????

          Anand Desai Developer Atharva Infotech

          I 1 Reply Last reply
          0
          • A Anand Desai

            Have you filled the Country DDl first in Update Form?? Then do following: 1. Run a query and get CountryID or CountryName What ever you want from Database for that perticular user. (Lets Take ID in this case) 2. write this code after getting CountryID:

            int intCountryID = .....; // ID u got from database
            for(int i=0;i<(ddlCountry.Length);i++)
            {
            if(ddlCountry[i].Value == intCountryID)
            ddlCountry.SelectedIndex = i;
            }

            3. Write this code into ddlCountry's SelectedIndexChanged property:

            .
            .
            .//write code to get cities for that country selected from database
            . here and load all cities into ddlCity
            .
            int intCityID = .....; // ID u got from database
            for(int j=0;j<ddlcity.length);j++)>
            {
            if(ddlCity[i].Value == intCityID )
            ddlCity.SelectedIndex = j;
            }

            4. Bingo!!! Problem Solved Got it?????????

            Anand Desai Developer Atharva Infotech

            I Offline
            I Offline
            Imran Khan Pathan
            wrote on last edited by
            #5

            Anand Desai wrote:

            int intCountryID = .....; // ID u got from database for(int i=0;i<(ddlCountry.Length);i++) { if(ddlCountry[i].Value == intCountryID) ddlCountry.SelectedIndex = i; }

            Just one line can do this.

            ddlCountry.SelectedValue=intCountryID.ToString();

            please don't forget to vote on the post that helped you.

            A 1 Reply Last reply
            0
            • I Imran Khan Pathan

              Anand Desai wrote:

              int intCountryID = .....; // ID u got from database for(int i=0;i<(ddlCountry.Length);i++) { if(ddlCountry[i].Value == intCountryID) ddlCountry.SelectedIndex = i; }

              Just one line can do this.

              ddlCountry.SelectedValue=intCountryID.ToString();

              please don't forget to vote on the post that helped you.

              A Offline
              A Offline
              Anand Desai
              wrote on last edited by
              #6

              That detailed code was to make Sandeep understand the basic procedure. Even I can imagine and understand what u wrote. but we have to explain all in simple language to that man. do u think Sandeep will digest as easily your line compare to my code?????????? Just wanted to teach how to think to our Juniors!!!

              Anand Desai Developer Atharva Infotech

              1 Reply Last reply
              0
              • S sandeep sangshetty

                Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

                S Offline
                S Offline
                Sandeep Akhare
                wrote on last edited by
                #7

                Here you will get lot of replies to your question but i bet you are not going to learn anything as you are not showing any efforts to tackle the problem. It seems that you are in learning phase for which you should always take help from google, there are n number of articles for developers which are in initial stage. Please try to learn first then if you stuck with any issue (atleast put some efforts )then ask question here that's the meaning of any forum. This is how you are going to learn :)

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

                A 1 Reply Last reply
                0
                • S Sandeep Akhare

                  Here you will get lot of replies to your question but i bet you are not going to learn anything as you are not showing any efforts to tackle the problem. It seems that you are in learning phase for which you should always take help from google, there are n number of articles for developers which are in initial stage. Please try to learn first then if you stuck with any issue (atleast put some efforts )then ask question here that's the meaning of any forum. This is how you are going to learn :)

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... " Check My Blog

                  A Offline
                  A Offline
                  Anand Desai
                  wrote on last edited by
                  #8

                  Very true.I m completely agree with u.

                  Anand Desai Developer Atharva Infotech

                  1 Reply Last reply
                  0
                  • S sandeep sangshetty

                    Hi friends,i have one task regarding drop down list. That is ,I have one registration form, in that i have one CITY drop down list,COUNTRY drop down list.I filled it and the city name ,country name should be loaded in the database. Now my requirement is,in update form the CITY name,COUNTRY name should come defaultly from database according to the user's registered CITY,COUNTRY name(in drop down list). please help me, i am new to .net

                    C Offline
                    C Offline
                    chandralekha
                    wrote on last edited by
                    #9

                    I think your update form's city dropdownlist and country dropdownlist contains list of city and country.And you want the particular city and country to come as selected. For that by using the select query you take the value to the form.You assign that to a string variable.For example the city value is assigned to strCity and country to strCountry.If the city's dropdownlist is DropDownList1 and country's is DropDownList2. Then you can use the following code if (DropDownList1.Items[0].Text == strCity) { DropDownList1.SelectedItem.Text =strCity; } else { DropDownList1.Items.Insert(0, strCity); } if (DropDownList2.Items[0].Text == strCountry) { DropDownList2.SelectedItem.Text =strCountry; } else { DropDownList2.Items.Insert(0, strCountry); } Hope This Code Help You

                    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