Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in retrieving records in dropdownlist box

Status
Not open for further replies.

meenakshidhar

Programmer
Oct 19, 2001
77
MY
hi,
My Code is given below...

HTML Code--
________________________________________________________
<asp:DropDownList id="cmbCountry" runat="server">
<asp:ListItem Value="Denmark">Denmark</asp:ListItem>
<asp:ListItem Value="USA">USA</asp:ListItem>
<asp:ListItem Value="India">India</asp:ListItem>
</asp:DropDownList>
_________________________________________________________



ASP Code--
__________________________________________________________
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim DS As DataSet

MyConnection = New SqlConnection("Data Source=INFO3783;" _
& "Initial Catalog=GTD_Test;User Id=gtd;Password=gtd;" _
& "Connect Timeout=15;Network Library=dbmssocn;")
MyCommand = New SqlDataAdapter("select * from GTD_M_ORG where LOCATION_ID=33", MyConnection)
DS = New DataSet()
MyCommand.Fill(DS)

' according to above query 'USA' should be selected...i m using this line..

cmbCountry.SelectedItem.Text = DS.Tables(0).Rows.Item(0).Item("COUNTRY_NAME")

'but it adds a new item as 'USA'..i mean USA comes twice in the dropdownlist...it should come only once..
________________________________________________________


Thx in advance...

Regards,
Meenakshi Dhar




 
this should work...i'm assuming your query only returns 1 row...

Code:
dim rowText as string = DS.Tables(0).Rows.Item(0).Item("COUNTRY_NAME")

cmbCountry.SelectedIndex = cmbCountry.Items.IndexOf(cmbCountry.Items.FindByText(rowText)
 
thx a lot checkai...its wrking now...

Regards,
Meenakshi Dhar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top