Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Populating from one combobox to another combobox in VB.NET

kishore13kishore13 Member Posts: 1
Hi !
I have two comboboxes in VB.NET. One is to display State from state table and another is used to display districts from district table. When i select a partiular state districts corresponding to that state only needs to be displayed.The problem is at the time of databinding combobox control what query i need to place in the Query builder of TableAdapter Configuration Wizard so that if i select a particular state districts corresponding to that state only needs to be displayed. I tried with creating SQL Dataadapters and datasets manually but it doesn't work out. Also i tried various types of SQL Server joins in Query Builder of TableAdapter Configuration Wizard but it doesn't work out. So pls help me regarding this problem.

Comments

  • s_sreenaths_sreenath Member Posts: 20
    In Html Page:


    Test Page















    In Code Behind:
    * Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    * If Not IsPostBack Then
    * Dim sqlConnection As New SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")
    * Dim sqlDataAdapter As New SqlDataAdapter("Select StateCode,Description from tblState", sqlConnection)
    * Dim dataTable As New DataTable()
    * sqlDataAdapter.Fill(dataTable)
    * stateDropDown.DataTextField = "Description"
    * stateDropDown.DataValueField = "StateCode"
    * stateDropDown.DataValueField = dataTable
    * stateDropDown.DataBind()
    * End If
    *
    * End Sub


    * Protected Sub stateDropDown_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    * Dim stateCode As String = stateDropDown.SelectedItem.Value.ToString()
    * Dim sqlConnection As New SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")
    * Dim sqlDataAdapter As New SqlDataAdapter("Select DistrictCode,Description from tblDistrict where StateCode=" & stateCode, sqlConnection)
    * Dim dataTable As New DataTable()
    * sqlDataAdapter.Fill(dataTable)
    * districtDropDOwn.DataTextField = "Description"
    * districtDropDOwn.DataValueField = "DistrictCode"
    * districtDropDOwn.DataValueField = dataTable
    * districtDropDOwn.DataBind()
    *
    * End Sub

    try out like this..........


    "Always Smile :)"
Sign In or Register to comment.