Re: Drop Down List Help by Arvind
Arvind
Fri May 14 09:13:14 CDT 2004
Dharmen,
I think what ravi has mentioned is correct.
That SelectedIndex_Change will work as u mentioned on change of
DropDownlist if that control has AutoPostBack = true.
ARvind
"Ravi" <anonymous@discussions.microsoft.com> wrote in message
news:C74F72DE-D905-4000-9326-C006C1905B32@microsoft.com...
> I am trying to represent master-detail records from a database.
> The general logic will be populating the first dropdownlist with the
master records and on change of the first dropdownlist
> getting the selectedindex and querying the database and populating the
childrecords in the second dropdownlist.
>
> But my question is how the same can be acheieved by using "Relations"?
>
> The following code fragment i tried, but i have no idea how to proceed.
>
> Thanks in advance
> Ravichandran
>
> Dim myconn As String
> Dim oledataadapt As New OleDbDataAdapter
> Dim oledataadapt1 As New OleDbDataAdapter
> Dim ds As New DataSet
> 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
>
> myconn = "Provider=MSDAORA;User ID=x;Password=x;Data Source=xxx;"
> oledataadapt = New OleDbDataAdapter("Select Organization_id from
bengine.cb_organization", myconn)
> oledataadapt.Fill(ds, "Sector")
>
> oledataadapt1 = New OleDbDataAdapter("Select Superbu_id,
organization_id from bengine.cb_super_businessunit", myconn)
> oledataadapt1.Fill(ds, "SBU")
> ds.Relations.Add("Sec_sbu",
ds.Tables("Sector").Columns("Organization_id"), _
> ds.Tables("SBU").Columns("Organization_id"))
> If Not IsPostBack Then
> DropDownList1.DataSource = ds.Tables(0).DefaultView
> DropDownList2.DataSource = ds.Tables(1).DefaultView
> DropDownList1.DataMember = "Organization_id"
> DropDownList2.DataMember = "superbu_id"
> DropDownList1.DataTextField = "Organization_id"
> DropDownList1.DataValueField = "Organization_id"
> DropDownList2.DataTextField = "superbu_id"
> DropDownList2.DataValueField = "superbu_id"
> DropDownList1.DataBind()
> DropDownList2.DataBind()
> End If
> End Sub
>
> Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
> Dim i As Integer
> i = DropDownList1.SelectedIndex
> DropDownList2.DataSource =
ds.Tables(0).Rows(i).GetChildRows("Sec_sbu")
> DropDownList2.DataTextField = "superbu_id"
> DropDownList2.DataValueField = "superbu_id"
> DropDownList1.DataBind()
> DropDownList2.DataBind()
> End Sub
>