View Single Post
  #1 (permalink)  
Old July 19th, 2003, 02:05 PM
vickeyurs vickeyurs is offline
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help: dropdownlist posting back gives random data


I have this dropdownlist which on postback gives random data from the list not the one we select :-) . i tried all the magic but still it wont work? please help if you could.

here is the Code for aspx followed by Code behind

Thanks in advance my friend

   <title>ASP.NET Database Dropdown List Sample</title>
   <form runat="server">
       <asp:DropDownList id="ddlMtg" runat="server"></asp:DropDownList>
       <asp:Button id="btnSubmit" onclick="SubmitBtn_Click" runat="server" text="Submit"></asp:Button>
       <asp:Label id="lblSelection" runat="server"></asp:Label>


_________________Code Behind

Imports System
Imports System.Web.HttpCookie
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.text.regularexpressions
Imports System.DateTime
Imports Microsoft.VisualBasic

Public Class dropdownlist : Inherits system.Web.UI.Page

   Dim myConnection As OleDbConnection
        Dim objCmd As OleDbCommand
        Dim DataReader As OleDbDataReader
        Dim strSQLQuery As String

   Protected WithEvents ddlmtg As System.Web.UI.WebControls.dropDownList

   Protected WithEvents lblSelection As System.Web.UI.WebControls.label

   Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button

        Sub Page_Load(sender As Object, e As EventArgs)
            ' Only pull data from db on first page call.
            If Not Page.IsPostBack Then

                ' Create connection and set connection string


            End If
        End Sub

        Sub SubmitBtn_Click(sender As Object, e As EventArgs)
            lblSelection.Text = "You selected the item in position " _
                & ddlmtg.SelectedItem.Value _
                & " which corresponds to the name " _
                & ddlmtg.SelectedItem.Text _
                & "."
        End Sub

       Public Sub CONNECTDB()

   myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/tipsmastera.mdb") & ";")

   End Sub

   Public Sub CONNECT_MTG()

   Dim strSql As String


   objCmd = New OleDbCommand(strSQLQuery, myConnection)

   dataReader = objCmd.ExecuteReader()
            With ddlmtg
               .DataSource = dataReader
               .DataTextField = "MTG"
               .DataValueField = "V"
            End With

   Catch exc As Exception

             If Not dataReader Is Nothing Then
             End If
             objCmd = Nothing
             If myConnection.State = ConnectionState.Open Then
             End If

             Trace.warn ("Mtg Text", ddlmtg.selecteditem.text)
   End Try

   End Sub

End Class
Reply With Quote