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!

Dropdownlist SelectedIndex returns incorrect value

Status
Not open for further replies.

rambleon

Programmer
Mar 6, 2004
130
IL
Hi,
I have a dropdown list with 6 items, clicking the first item is ok - SelectedIndex = 0, clicking any other item the SeletedIndex = 1. I have the loading and binding for the dropdownlist in a If Not Page.IsPostBack block.
Any ideas ?
 
Post the relevant code and we can take a look.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here's the relevent code:

Imports System.Data.OleDb
Imports System
Imports System.IO
Public Class TlushFrm
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TlushDate As System.Web.UI.WebControls.DropDownList
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents my As System.Web.UI.WebControls.TextBox
Protected objConn As New OleDbConnection(ConfigurationSettings.AppSettings("dsn"))
Protected objDA As OleDbDataAdapter
Protected objDS As New DataSet()
Protected objDV As DataView



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
objDA = New OleDbDataAdapter("Select * From TlushOffset Where IDNmber = " & WebForm1.ZehutStr, objConn)
objDA.Fill(objDS, "TlushOffset")
objDV = objDS.Tables("TlushOffset").DefaultView
TlushDate.DataSource = objDV
TlushDate.DataValueField = "Offset_and_Len"
TlushDate.DataTextField = "PayslipYYMM"
TlushDate.DataBind()
End If
DispTlush(WebForm1.ZehutStr, Mid(TlushDate.Items(0).Text, 3, 2), Right(TlushDate.Items(0).Text, 2), TlushDate.Items(0).Value)
End Sub
Private Sub TlushDate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TlushDate.SelectedIndexChanged
Response.Clear()
DispTlush(WebForm1.ZehutStr, Mid(TlushDate.SelectedItem.Text, 3, 2), Right(TlushDate.SelectedItem.Text, 2), TlushDate.SelectedItem.Value)
End Sub


 
Rather than than call any functions (like when you call "DispTlush") to test what may be going wrong, try using something simple like:
Code:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            objDA = New OleDbDataAdapter("Select * From TlushOffset Where IDNmber = " & WebForm1.ZehutStr, objConn)
            objDA.Fill(objDS, "TlushOffset")
            objDV = objDS.Tables("TlushOffset").DefaultView
            TlushDate.DataSource = objDV
            TlushDate.DataValueField = "Offset_and_Len"
            TlushDate.DataTextField = "PayslipYYMM"
            TlushDate.DataBind()
        End If
    End Sub

    Private Sub TlushDate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TlushDate.SelectedIndexChanged
        Response.Write(TlushDate.SelectedItem.Value)
    End Sub


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I tried what you suggested the 1st and 2nd items return the correct value all other items return the value for the second item or nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top