Results 1 to 5 of 5

Thread: Countries Capital DropdownList

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Answers
    15

    Countries Capital DropdownList

    Hi I am a beginner to asp.net.
    Could any one please help me ...
    I have a database table with two colums ( column one has all the countries and column two has all the capitols of that particular country.)

    In my .aspx page I have a dropdown list and a text box.
    Drop downlist will display all the countries and if I select a country then its capitol should be displayed in the textbox.

    Thanks in Advance...
    Your help is much appreciated....


  2. #2
    Contributing Member
    Join Date
    Jun 2007
    Answers
    65

    Re: Countries Capital DropdownList

    Quote Originally Posted by ushalakshmi View Post
    Hi I am a beginner to asp.net.
    Could any one please help me ...
    I have a database table with two colums ( column one has all the countries and column two has all the capitols of that particular country.)

    In my .aspx page I have a dropdown list and a text box.
    Drop downlist will display all the countries and if I select a country then its capitol should be displayed in the textbox.

    Thanks in Advance...
    Your help is much appreciated....
    Hi Usha,

    Bind the dropdown list with DataTextField as the countryName and DataValueField as capital

    then in onSelectedIndex_Change event of dropdown write code like
    TextBox1.Text = DropDownList1.SelectedValue


    ---V V---
    Vikas Vaidya

    [Please mark the post as Thank if u find the answer useful]


  3. #3
    Junior Member
    Join Date
    Apr 2008
    Answers
    2

    Re: Countries Capital DropdownList

    You have told that you have two clomns. 1.dropdownlist,2.text box and second one should nit be a textbox. It should be a another dropdownlist. If you are using sql server initially you have to create table for country. Then you have to create nexttable for capitals. For example create table capitals(capital nvarchar(10)) insert into capitals (capital)values(delhi) totally you have to create 3 loaddrop() 1.edit 2.to bind datatextfield ofcapitals 3.if u click any countries to show capitals as well as u have to write in your home page like if(!pageispostback) { loaddrop(); }


  4. #4
    Junior Member
    Join Date
    Apr 2008
    Answers
    1

    Re: Countries Capital DropdownList

    For displaying country private sub binddropdown() try dim da as new sqldataadapter("select * from countries order by country", myconnection) dim ds as new dataset myconnection.open() da.fill(ds) myconnection.close() dropdownlist1.datatextfield = "country_name" dropdownlist1.datavaluefield = "country_id" dropdownlist1.datasource = ds dropdownlist1.databind() catch ex as exception end try end sub then you have to write code on dropdownlist1_selectedindexchanged cmd = new sqlcommand("sp_capital", myconnection) ' here i am using stored procedue or u can use the sqlquery directly /* create procedure sp_capital @countryid as integer as begin select ----------- where dbo.city.country_id=@countryid end go*/ cmd.commandtype = commandtype.storedprocedure cmd.parameters.add("@countryid", sqldbtype.int) cmd.parameters("@countryid").value = dropdownlist1.selectedvalue.trim() da = new sqldataadapter(cmd) da.fill(ds) myconnection.open() cmd.executenonquery() myconnection.close() end sub hope this will find u useful


  5. #5

    Re: Countries Capital DropdownList

    Quote Originally Posted by ushalakshmi View Post
    Hi I am a beginner to asp.net.
    Could any one please help me ...
    I have a database table with two colums ( column one has all the countries and column two has all the capitols of that particular country.)

    In my .aspx page I have a dropdown list and a text box.
    Drop downlist will display all the countries and if I select a country then its capitol should be displayed in the textbox.

    Thanks in Advance...
    Your help is much appreciated....


    First u connect to the database,retrieve all the countries and bind it to the dropdownlist,u have to bind it if it is not postback ie:firsttime
    if(!postback)
    Dropdown list is having selected_Index_changed

    on that event u take the selected country value into the variable

    pass the variable as parameter to the stored procedure and take the capital of that country and bind it to the textbox control


  6.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact