Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > binding tables with relationes to 2 dropdownlist

Reply
Thread Tools

binding tables with relationes to 2 dropdownlist

 
 
barney
Guest
Posts: n/a
 
      03-04-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
DotNetJerome
Guest
Posts: n/a
 
      03-04-2005
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
> (E-Mail Removed)
>

 
Reply With Quote
 
 
 
 
J L
Guest
Posts: n/a
 
      03-04-2005
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
>> (E-Mail Removed)
>>


 
Reply With Quote
 
barney
Guest
Posts: n/a
 
      03-05-2005
Hi Jerome & John

Thanks for your quick answers.
Jerome said:
> >I don't find any dependency between your queries....


I tried to do the dependencies through the Relation of the dataset. In
Windows Programming with ADO & C# this works quite well.
In ASPX I think I will do it like you showed me...

Example Windows Programming:
// ADD Dependency ( Relation ) to Comboboxes:
// -> _ds is my Dataset with 2 Tables
_ds.Relations.Add("trosymptom1_trosymptom2",
_ds.Tables["trosymptom1"].Columns["key1"],
_ds.Tables["trosymptom2"].Columns["key1"]);

cboSymptom1Tech.DataSource = _ds;
cboSymptom1Tech.DisplayMember = "trosymptom1.text";
cboSymptom1Tech.ValueMember = "trosymptom1.key1";

// If you pass the relation here your 2nd combobox will only show
// the entries matching Combobox 1
cboSymptom2Tech.DataSource = _ds;
// Syntax: ParentTable -> Relation -> columnname of childetable
cboSymptom2Tech.DisplayMember =
"trosymptom1.trosymptom1_trosymptom2.text";
cboSymptom2Tech.ValueMember =
"trosymptom1.trosymptom1_trosymptom2.key2";

I'm no experienced Webprogrammer and hoped that this would work also
with DropDownBoxes, cause I like this feature very much in Windows
Programming ...

regards & thanks

Tobias

b-gumble@_nospam_gmx.net remove the _nospam_

J L <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> 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
> >> (E-Mail Removed)
> >>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get database metadata information (i.e. existing tables and columns in tables) Chris Brat Python 5 08-22-2006 05:25 PM
Binding tables interesection with GridView/ObjectDataSource [newbie] H5N1 ASP .Net 0 03-27-2006 03:34 AM
Tables within tables Otuatail HTML 7 08-02-2004 04:42 AM
Text after 2 tables actually appears between 2 tables ! Peter Bassett HTML 3 08-15-2003 06:46 PM
Multiple tables not displayed when binding to a Repeater Jim French ASP .Net 0 07-18-2003 01:46 PM



Advertisments