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

Dani AI

Generated

is on the right track about reading the saved record and is correct to insist on using id fields for binding. The reliable pattern is: keep countries/cities as normalized tables, store the city (or city_id) in the user row, and restore the selections by binding lists and then applying the saved ids — but with a few practical safeguards.

Database/design checklist:

  • Separate tables: Countries(CountryId, Name), Cities(CityId, Name, CountryId). Store CityId (FK) in the registration table rather than the raw city name. Add FK constraints and an index on Cities.CountryId.
  • Use parameterized queries or stored procedures (do not concatenate user input into SQL).

Page-flow to populate the update form:

  • On initial page load (not postback) bind the country dropdown (DataTextField = name, DataValueField = id).
  • Load the user record and get the saved CityId. From that CityId determine the CountryId.
  • Set the country selection first, then bind the city dropdown filtered by that country, then set the city selection.
  • If the stored CityId is missing from the current city list (data drift), insert a temporary list item with that city name/id and select it so the user sees their saved value.

Common pitfalls and quick fixes:

  • Do not rebind dropdowns on every postback — wrap binds in an IsPostBack check.
  • Ensure types match: SelectedValue expects the same string form as the DataValueField.
  • For cascading lists use AutoPostBack or a client-side AJAX refresh to avoid full postbacks.
  • If adding manual items before binding, set AppendDataBoundItems = true.

For details on the control behavior see the Microsoft ListControl/SelectedValue docs: ListControl.SelectedValue.

Recommended Answers

All 2 Replies

u just use a query to retrieve the results
use this query

Dim con As New dbAccess
          str = "SELECT a.Title, a.FirstName, a.FamilyName, a.Fee, f.FeePaid, f.FeeDue, f.Instalments, f.Inst_Amounts, f.Inst_Amounts_updated, f.Inst_Dates, f.Inst_com_paid, f.FeeStatus, f.Inst_Paid_Amount FROM ApplyOnline a, FeeDetails f where a.refno = f.refno and a.refno ='" & Trim(txtstdrefno.Text) & "'"
        con.ds = con.ExeR(str)
        If con.ds.Tables(0).Rows.Count - 1 >= 0 Then
lblStudentName.Text = con.ds.Tables(0).Rows(0).Item(0) & "." & con.ds.Tables(0).Rows(0).Item(1) & " " & con.ds.Tables(0).Rows(0).Item(2)
        txttotfee.Text = con.ds.Tables(0).Rows(0).Item(3)
                  Else
                   End If

taking above as a example u can achieve u r functionality

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

Your tables of city, state and country must have a id field. When you are binding the data from the database then bind the value field of drop down to the id field and save the id of state or country in the database. When you edit the record then fetch the record, bind the drop down with all the data(state/country) and write one line
dropdown1.selectedvalue=dt.rows[0]["stateid"].tostring();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.