Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello programmers, got a problem here(as always). as you see ive bind data to the 2 dropdown, the first 1 is the root of the second dropdown and the 2 dropdown is the root of the textboxes. so far no problem regarding that matter. now here is my problem when i choose another value on the second dropdown the data from it returns to the first value;
plss help.. thanks in advance and more power
Code:
VB
Imports System.Math
Imports System.Web
Imports System.Data.SqlClient
Imports System.Data
Partial Class PlanvsAct
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (IsPostBack = False) Then
            categorybind()
        End If
        coursecodebind()
        binddata()
    End Sub

    Public Sub categorybind()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select [Category] from [tblCategory]"
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        ddcategory.DataSource = command.ExecuteReader
        ddcategory.DataTextField = "Category"
        ddcategory.DataValueField = "Category"
        ddcategory.DataBind()
        connection.Close()
    End Sub

    Public Sub coursecodebind()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select CourseCode from tblTrainingPlan where ([Category] LIKE '%' + @Category + '%')"
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        command.Parameters.AddWithValue("@Category", ddcategory.SelectedValue)
        ddcoursecode.DataSource = command.ExecuteReader
        ddcoursecode.DataTextField = "CourseCode"
        ddcoursecode.DataValueField = "CourseCode"
        ddcoursecode.DataBind()
        connection.Close()
    End Sub
    Public Sub binddata()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select * from tblTrainingPlan where ([CourseCode] LIKE '%' + @CourseCode + '%')"
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        command.Parameters.AddWithValue("@CourseCode", ddcoursecode.SelectedValue)
        Dim datareader As SqlClient.SqlDataReader = command.ExecuteReader
        Do While datareader.Read()
            txtTitle.Text = (datareader("CourseTitle").ToString)
            txtcollege.Text = (datareader("College").ToString)
            txtDuration.Text = (datareader("Duration").ToString)
        Loop
        connection.Dispose()
        connection.Close()
    End Sub



    Public Sub control()
        If ddcoursecode.SelectedValue = "" Then
            txtTitle.Text = ""
            txtcollege.Text = ""
            txtDuration.Text = ""
        End If
    End Sub
End Class
Posted
Updated 1-Jun-11 16:16pm
v3

It will return to first selection as on page_load you have called the coursecodebind(). So as soon as you click inside any of the Dropdowns, the page will postback and the first thing it will do is reinitialize your dropdown. Keep the coursecodebind() function inside the isPostback condition.

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (IsPostBack = False) Then
        categorybind()
        coursecodebind()
        binddata()
    End If
End Sub
 
Share this answer
 
Comments
janwel 2-Jun-11 0:39am    
sir ive already done that but it still not working
try with this

if(!ispostback)
{
//your code
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900