Re: binding tables with relationes to 2 dropdownlist

From: J L (john_at_marymonte.com)
Date: 03/04/05


Date: Fri, 04 Mar 2005 11:06:42 -0800

Hi Barney and Jerome,
I am a newbie to ADO.Net and VB.Net. The idea of binding two dropdown
lists as you discuss is very interesting to me. My question, once the
dataadapters and binding are set as shown, do you need to add any code
to the event of the parent dropdown list or does a change in its
selected value automatically cause the second list to update?

TIA,
John
On Fri, 4 Mar 2005 04:31:02 -0800, DotNetJerome
<reachjerome@_yahoo.com-remove-the-underscore-after@> wrote:

>Hi Barney,
>
>I don't find any dependency between your queries....
>
>Your second query suppose to be as follows.
>
>"select id_po,quantity from wrk_order where id_vendor=" +
>DropDownList1.SelectedItem.Value
>
>Now, when you execute your second query it will get the values from the
>wrk_order table for the selected vendor id avilable in the first dropdown
>list box.
>
>Cheers,
>
>Jerome. M
>
>"barney" wrote:
>
>> Hi,
>> I'm trying to get a kind of dependency to 2 dropdownlists in asp.net:
>>
>> |Dropdown Vendor| -> 1:n -> |Dropdown Order|
>>
>> After selecting a Vendor the 2nd Dropdownbox should only show Orders
>> linked to the selected Vendor. ( Both Dropdowns do autopostback )
>> But it always shows all values ...
>> Maybee someone has a tip for me ...
>>
>> I trY:
>> if ( ! Page.IsPostBack ) {
>> string dsn = "...";
>> SqlConnection sql = new SqlConnection( dsn );
>> SqlCommand cmd1 = new SqlCommand("select id_vendor, name from
>> def_vendor", sqlC);
>> SqlCommand cmd2 = new SqlCommand("select id_vendor, id_po, quantity
>> from wrk_order", sqlC);
>> sqlC.Open();
>> SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
>> SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
>> ds = new DataSet("myds");
>>
>> da1.Fill( ds, "vendor" );
>> da2.Fill (ds, "po" );
>>
>> ds.Relations.Add("map_vendor_po",
>> ds.Tables["vendor"].Columns["id_vendor"],
>> ds.Tables["po"].Columns["id_vendor"]);
>> DropDownList1.DataSource = ds.Tables["vendor"];
>> DropDownList1.DataTextField = "name";
>> DropDownList1.DataValueField = "id_vendor";
>> DropDownList1.DataBind();
>>
>> DropDownList2.DataSource = ds.Relations["map_vendor_po"].ChildTable;
>> DropDownList2.DataTextField = "id_po";
>> DropDownList2.DataValueField = "id_po";
>> DropDownList2.DataBind();
>>
>> }
>>
>> Many thanks in advance
>> Tobias
>> b-gumble@gmx.net
>>