473,785 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dropdownlist - relations-asp.net-how to?

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 dropdownlis
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 advanc
Ravichandra

Dim myconn As Strin
Dim oledataadapt As New OleDbDataAdapte
Dim oledataadapt1 As New OleDbDataAdapte
Dim ds As New DataSe
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Loa
'Put user code to initialize the page her

myconn = "Provider=MSDAO RA;User ID=x;Password=x ;Data Source=xxx;
oledataadapt = New OleDbDataAdapte r("Select Organization_id from bengine.cb_orga nization", myconn
oledataadapt.Fi ll(ds, "Sector"

oledataadapt1 = New OleDbDataAdapte r("Select Superbu_id, organization_id from bengine.cb_supe r_businessunit" , myconn
oledataadapt1.F ill(ds, "SBU"
ds.Relations.Ad d("Sec_sbu", ds.Tables("Sect or").Columns("O rganization_id" ),
ds.Tables("SBU" ).Columns("Orga nization_id")
If Not IsPostBack The
DropDownList1.D ataSource = ds.Tables(0).De faultVie
DropDownList2.D ataSource = ds.Tables(1).De faultVie
DropDownList1.D ataMember = "Organization_i d
DropDownList2.D ataMember = "superbu_id
DropDownList1.D ataTextField = "Organization_i d
DropDownList1.D ataValueField = "Organization_i d
DropDownList2.D ataTextField = "superbu_id
DropDownList2.D ataValueField = "superbu_id
DropDownList1.D ataBind(
DropDownList2.D ataBind(
End I
End Su

Private Sub DropDownList1_S electedIndexCha nged(ByVal sender As Object, ByVal e As System.EventArg s) Handles DropDownList1.S electedIndexCha nge
Dim i As Intege
i = DropDownList1.S electedInde
DropDownList2.D ataSource = ds.Tables(0).Ro ws(i).GetChildR ows("Sec_sbu"
DropDownList2.D ataTextField = "superbu_id
DropDownList2.D ataValueField = "superbu_id
DropDownList1.D ataBind(
DropDownList2.D ataBind(
End Su


Nov 18 '05 #1
1 1439
If I understand you correctly, you're trying to do is fetch data from
the server to populate the second dropdown. So don't think Relations,
think WHERE clause in your SELECT statement. If you've already fetched
the data into another DataTable in the DataSet, then you can set the
relations.

--Mary

On Sun, 16 May 2004 21:16:02 -0700, "Ravi"
<an*******@disc ussions.microso ft.com> wrote:
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 OleDbDataAdapte r
Dim oledataadapt1 As New OleDbDataAdapte r
Dim ds As New DataSet
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here

myconn = "Provider=MSDAO RA;User ID=x;Password=x ;Data Source=xxx;"
oledataadapt = New OleDbDataAdapte r("Select Organization_id from bengine.cb_orga nization", myconn)
oledataadapt.Fi ll(ds, "Sector")

oledataadapt1 = New OleDbDataAdapte r("Select Superbu_id, organization_id from bengine.cb_supe r_businessunit" , myconn)
oledataadapt1.F ill(ds, "SBU")
ds.Relations.Ad d("Sec_sbu", ds.Tables("Sect or").Columns("O rganization_id" ), _
ds.Tables("SBU" ).Columns("Orga nization_id"))
If Not IsPostBack Then
DropDownList1.D ataSource = ds.Tables(0).De faultView
DropDownList2.D ataSource = ds.Tables(1).De faultView
DropDownList1.D ataMember = "Organization_i d"
DropDownList2.D ataMember = "superbu_id "
DropDownList1.D ataTextField = "Organization_i d"
DropDownList1.D ataValueField = "Organization_i d"
DropDownList2.D ataTextField = "superbu_id "
DropDownList2.D ataValueField = "superbu_id "
DropDownList1.D ataBind()
DropDownList2.D ataBind()
End If
End Sub

Private Sub DropDownList1_S electedIndexCha nged(ByVal sender As Object, ByVal e As System.EventArg s) Handles DropDownList1.S electedIndexCha nged
Dim i As Integer
i = DropDownList1.S electedIndex
DropDownList2.D ataSource = ds.Tables(0).Ro ws(i).GetChildR ows("Sec_sbu")
DropDownList2.D ataTextField = "superbu_id "
DropDownList2.D ataValueField = "superbu_id "
DropDownList1.D ataBind()
DropDownList2.D ataBind()
End Sub



Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2428
by: kamaumalone | last post by:
I have a dropdownlist which lives inside of a repeater. The repeater accepts user input via textboxes and the aforementioned dropdownlist. The repeater accepts phone numbers and allows for an arbitrary number of empty rows to be added to it. So, if a user knew in advance that they wanted to add 3 phone numbers, they can type the nuber '3' in a textbox (outside the repeater) and click a button (also outside of a repeater), and 3 new empty ...
1
1804
by: Jef De Rycke | last post by:
Hi access group, I have written code to create relations between tables according to a corresponding relations information table. At first I thought my code was not working properly because after running the code the relations don't show in the relations window. However when I enter data in an underlying table I get referential integrity error messages so the relations does actually exist. The created relations do show in the relations...
0
1186
by: PJ | last post by:
I have several dropdownlist controls in a placeholder on my form. Certain events will show this place holder and populate the values of the items collection of the dropdownlist controls. A placeholder surrounds each individual dropdownlist as well and will be set to false if the data for the dropdownlist will not cause it to have more than one item. I create the items manually...I don't use databinding and I set both the text and the...
0
1187
by: Joe Van Meer | last post by:
Hi all, I have a question regarding data relations within a data set. Say I have 3 tables named CLIENT, BOOKING and EMPLOYEE and I wanted to relate the first two tables (CLIENT AND BOOKING) via a clientid and relate the second set of tables (BOOKING AND EMPLOYEE) using an employeeid. My problem arises when there a re no records in one of the tables in either data relation. What is the best way to handle this, check the number of...
3
6202
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest") enables me to work with ddlTest - with, for example, ddlTest.SelectedValu However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object reference not set to an instance of an object.
15
3132
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
0
836
by: shahDeveloper | last post by:
i have created a number of combo boxes according to my need.no i want to save the changes when any one click update button,but here the control did not find by findcontrol function. Dim i, j, totc As Long, FcNo As String, cmbcat As Object, fid As ArrayList catarry = New ArrayList catarry = CType(ViewState("catgs"), ArrayList) totc = CLng(ViewState("totcts")) For i = 0 To totc - 1 'for category combo box 'cmbcat = New Object 'cmbcat =...
14
1714
by: kjewell23 | last post by:
Hi. I have the code working just fine except all the data isn't coming up with the ds.relations code. Could you see what I'm doing wrong or what else I need to add. Code down below Dim adapter As OdbcDataAdapter = New OdbcDataAdapter(command) Dim ds As DataSet = New DataSet() adapter.SelectCommand = New OdbcCommand("select rmsfiles2.obcop200.line#, rmsfiles2.obcop200.ordno, rmsfiles2.obcop200.quano, rmsfiles2.obcop200.quana,...
3
5472
chathura86
by: chathura86 | last post by:
hi, i have a table which has child rows in another table. Now i want to truncate this table temporally, because i will re-enter those values in a short time with some changes. cannot use update statement to make those changes. only possible way is truncating and inserting. also i want to insert some data in to child rows without any parent rows. as in the previous section i can add the relevant parent rows shortly. its like i want to...
0
3501
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.