View Single Post
  #1 (permalink)  
Old February 15th, 2012, 12:39 PM
shariful shariful is offline
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2010
Posts: 13
Thanks: 3
Thanked 0 Times in 0 Posts
Default DropDownList.SelectedValue - NOT working

Helo
I have databinded some values from a Sql 2005 database table into a dropdown list.
My problem is in trying to get the selected value from the dropdown list so I can use it.
What is happening is that I am only getting the selected index of the selected value in the dropdown list. But I want to get the selected value NOT the selected index. My codes are as below:

<asp:DropDownList ID="ddlCountry" runat="server" Width="255px" TabIndex="11"
DataSourceID="ds_Countries" DataTextField="CountryName"
DataValueField="CountryId" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem>Please Select Country</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="ds_Countries" runat="server"
ConnectionString="<%$ ConnectionStrings:MyPeopleConnectionString1 %>"
SelectCommand="SELECT [CountryId], [CountryName] FROM [Countries] ORDER BY [CountryName]">
</asp:SqlDataSource>

Private Function CollectUserContactDetails() As UserContactDetail

Dim ucd As New UserContactDetail


ucd.Postcode = Me.txtPostcode.Text.Trim()

ucd.Country = Me.ddlCountry.SelectedValue ‘Not working

ucd.HomeTelephoneNumber = Me.txtHomeTelephone.Text
ucd.WorkTelephoneNumber = Me.txtWorkTelephone.Text
ucd.MobileNumber = Me.txtMobileNumber.Text

Return ucd

End Function
Any help will be highly appreciated.

Thanks
Sharif