Solved

getting the selected value for an asp.net 3.5 dropdownlist

Posted on 2010-08-18
7
378 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
7 Comments
 
LVL 27

Expert Comment

by:nmarun
Comment Utility
Hello MatovuAnthony,

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


Regards,

Arun
0
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
Comment Utility
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
Comment Utility
Place the item fill / databound code in the page load like below:
if (!IsPostBack)
{
     //databind / fill method goes here
}
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 21

Assisted Solution

by:Tapan Pattanaik
Tapan Pattanaik earned 100 total points
Comment Utility
0
 
LVL 1

Author Comment

by:Anthony Matovu
Comment Utility


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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now