Solved

getting the selected value for an asp.net 3.5 dropdownlist

Posted on 2010-08-18
7
382 Views
Last Modified: 2013-11-27
I have a list of items in an asp.net drop down list. but when i select the selectedvalue is always the first item in the list.

Help
0
Comment
Question by:Anthony Matovu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 33472294
Hello MatovuAnthony,

Please post some code as to what exactly you're doing.


Regards,

Arun
0
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 33472295
check your Databind to dropdownlist, whether Databind twice. can you post sample code?
0
 
LVL 18

Assisted Solution

by:Ajay Sharma
Ajay Sharma earned 400 total points
ID: 33472319
Place the item fill / databound code in the page load like below:
if (!IsPostBack)
{
     //databind / fill method goes here
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Assisted Solution

by:Tapan Pattanaik
Tapan Pattanaik earned 100 total points
ID: 33472339
0
 
LVL 1

Author Comment

by:Anthony Matovu
ID: 33472366


The code i am using is below.

but at line xxxxx the dr1.selectedvalue is always = 0

Thanks

Anthony

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        z.Load(MapPath("~/FieldLabels.xml"))
        Dim labs As XmlNodeList = z.SelectNodes("/questions/section/question[@qid='q36']/answer")
        dr1.Items.Clear()
        dr1.Items.Add(New ListItem(" ", 0))
     
        For Each lab As XmlNode In labs
            Me.dr1.Items.Add(New ListItem(lab.InnerText, lab.Attributes.ItemOf(0).Value))
        Next
  End Sub
      

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim uacDb As New System.Data.SqlClient.SqlConnection
        Dim dcmd As New System.Data.SqlClient.SqlCommand
        Dim tsql As String
        Dim tstr As String
        Try
            uacDb = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("dbase").ToString)
            uacDb.Open()

            tstr = "INSERT INTO [qn36] (bseqno,"
            tsql = " values(" & Session("agency") & ","

           xxxxxx
 If Not dr1.SelectedValue = "0" Then
                tsql = Trim(tsql) & dr1.SelectedValue & ","
                tstr = Trim(tstr) & "[qn36c1]" & ","
                If Trim(qn36c10a.Text & "").Length > 0 Then : tsql = Trim(tsql) & qn36c10a.Text & "," : tstr = Trim(tstr) & "[qn36c10]" & "," : End If
                If Trim(qn36c9a.Text & "").Length > 0 Then : tsql = Trim(tsql) & qn36c9a.Text & "," : tstr = Trim(tstr) & "[qn36c9]" & "," : End If
                If Trim(qn36c8a.Text & "").Length > 0 Then : tsql = Trim(tsql) & qn36c8a.Text & "," : tstr = Trim(tstr) & "[qn36c8]" & "," : End If
    End If
0
 
LVL 18

Accepted Solution

by:
Ajay Sharma earned 400 total points
ID: 33472388
If Not Page.IsPostBack Then
z.Load(MapPath("~/FieldLabels.xml"))
        Dim labs As XmlNodeList = z.SelectNodes("/questions/section/question[@qid='q36']/answer")
        dr1.Items.Clear()
        dr1.Items.Add(New ListItem(" ", 0))
     
        For Each lab As XmlNode In labs
            Me.dr1.Items.Add(New ListItem(lab.InnerText, lab.Attributes.ItemOf(0).Value))
        Next
 
End If
0
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 33472398
Here i attached modified code.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

if not ispostback then
        z.Load(MapPath("~/FieldLabels.xml"))
        Dim labs As XmlNodeList = z.SelectNodes("/questions/section/question[@qid='q36']/answer")
        dr1.Items.Clear()
        dr1.Items.Add(New ListItem(" ", 0))
     
        For Each lab As XmlNode In labs
            Me.dr1.Items.Add(New ListItem(lab.InnerText, lab.Attributes.ItemOf(0).Value))
        Next
End if
  End Sub

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question