[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

getting the selected value for an asp.net 3.5 dropdownlist

Posted on 2010-08-18
7
Medium Priority
?
385 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 1600 total points
ID: 33472319
Place the item fill / databound code in the page load like below:
if (!IsPostBack)
{
     //databind / fill method goes here
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 21

Assisted Solution

by:Tapan Pattanaik
Tapan Pattanaik earned 400 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 1600 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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