DropDown Boxes for data entry of fixed fields

W

Wingot

Hey,



I have a program I am trying to write using Visual C#, SQL Server
2005/2008, and Visual Studio 2008, and one part of it includes a Schema
called Client. Inside this schema, three tables exist named Country,
MedicalCondition, and Customer.



The Customer table includes various fields, but the important ones for
this problem are MedicalCondition, Country, BillTo, EmergencyContact1
and EmergencyContact2.



What I want to do is have each of these five fields, which are linked
via foreign keys, as selectable dropdown boxes. The Customer entry view
is using Details view, not a DataGrid view, and so I am having
difficulty figuring out how to do this.



As an example, when someone clicks on the dropdown for MedicalCondition,
it should display the MedicalCondition.Name fields as the options. When
they select one, it places the MedicalCondition.MedicalConditionID into
the MedicalCondition field of the Customer database.



Any help greatly appreciated.



Regards,

Wingot
 
N

Nicholas Paldino [.NET/C# MVP]

Wingot,

First, you need to make sure that you have the data loaded for those
tables. Once you have that, you can set the dropdowns to use those for the
list through the DataSource/DataMember properties.

You would also bind the value to the field that contains the id.

The glue that wraps this all up is the DisplayMember and ValueMember
properties on the dropdown. You would set the DisplayMember property to the
member you wish to display in the drop down, while the ValueMember would be
set to the member which would provide the value which would be used for the
binding for the value.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hey,

I have a program I am trying to write using Visual C#, SQL Server 2005/2008,
and Visual Studio 2008, and one part of it includes a Schema called Client.
Inside this schema, three tables exist named Country, MedicalCondition, and
Customer.

The Customer table includes various fields, but the important ones for this
problem are MedicalCondition, Country, BillTo, EmergencyContact1 and
EmergencyContact2.

What I want to do is have each of these five fields, which are linked via
foreign keys, as selectable dropdown boxes. The Customer entry view is using
Details view, not a DataGrid view, and so I am having difficulty figuring
out how to do this.

As an example, when someone clicks on the dropdown for MedicalCondition, it
should display the MedicalCondition.Name fields as the options. When they
select one, it places the MedicalCondition.MedicalConditionID into the
MedicalCondition field of the Customer database.

Any help greatly appreciated.

Regards,
Wingot
 
S

Steven Cheng[MSFT]

Hi Wingot,

From your description, my understanding is that you want to build a data
page for data inserting and for the record to inserting, it may contain
several fields and these fields need to be selected via some
dropdownlists(these lists will display human readable name and actually
send the underlying ID into database), correct?

As for such case, I think you can use the following approach:

** you can use multiple datasource controls and each one bind to a certain
list(each datasource use a query to selected the list of a certain field)

**Your DetailsView may connect to database through another datasource and
the query for this datasource will return the underlying ID for those
fields. thus, you just bind those ID value to the SelectedValue of those
DropDownlists

How do you think? If there is anything unclear, please feel free to post
here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

=

--------------------
 
W

Wingot

Hi Steven,

AS for creating multiple datasources, I had attempted to do this, and
despite the fact that in Preview Data it worked, I couldn't get it to
display anything in the dropdown boxes (or Combobox controls to be
technical) once I had associated the data.

I will have another look at it when I get home, and will post an update.

Regards,
Wingot
-----Original Message-----
From: Steven Cheng[MSFT] [mailto:[email protected]]
Posted At: Monday, 3 December 2007 7:34 PM
Posted To: microsoft.public.dotnet.languages.csharp
Conversation: DropDown Boxes for data entry of fixed fields
Subject: RE: DropDown Boxes for data entry of fixed fields

Hi Wingot,

From your description, my understanding is that you want to build a
data
page for data inserting and for the record to inserting, it may contain
several fields and these fields need to be selected via some
dropdownlists(these lists will display human readable name and actually
send the underlying ID into database), correct?

As for such case, I think you can use the following approach:

** you can use multiple datasource controls and each one bind to a
certain
list(each datasource use a query to selected the list of a certain
field)

**Your DetailsView may connect to database through another datasource
and
the query for this datasource will return the underlying ID for those
fields. thus, you just bind those ID value to the SelectedValue of
those
DropDownlists

How do you think? If there is anything unclear, please feel free to
post
here.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.

=

--------------------
From: "Wingot" <[email protected]>
Subject: DropDown Boxes for data entry of fixed fields
Date: Sun, 2 Dec 2007 15:44:43 +0900

Hey,



I have a program I am trying to write using Visual C#, SQL Server
2005/2008, and Visual Studio 2008, and one part of it includes a Schema
called Client. Inside this schema, three tables exist named Country,
MedicalCondition, and Customer.



The Customer table includes various fields, but the important ones for
this problem are MedicalCondition, Country, BillTo, EmergencyContact1
and EmergencyContact2.



What I want to do is have each of these five fields, which are linked
via foreign keys, as selectable dropdown boxes. The Customer entry view
is using Details view, not a DataGrid view, and so I am having
difficulty figuring out how to do this.



As an example, when someone clicks on the dropdown for MedicalCondition,
it should display the MedicalCondition.Name fields as the options. When
they select one, it places the MedicalCondition.MedicalConditionID into
the MedicalCondition field of the Customer database.



Any help greatly appreciated.



Regards,

Wingot
 
W

Wingot

Hey Nicholas,

Sorry that I had not responded earlier, have been rather busy the past
two days.

I had done this, and got it to work for a time in the Country field,
using a Combobox. I have subsequently broken it when trying to get
Medical Condition to work, and it now no longer displays anything in
that Combobox, but the fact that I have seen it in action gives me hope.

As a query, there is no reason why this shouldn't work for a recursive
field is there? Specifically, the Customer table refers back to itself
for the Bill To and Emergency Contact #1 and #2 fields.

Regards,
Wingot
 
S

Steven Cheng[MSFT]

Hi Wingot,

Thanks for your reply.

For multiple datasource control, if the field list is constant or not
frequently changed, you can apply Cache on each of them so that they will
not impact the page's performance much.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
W

Wingot

Hey,

I have attempted to add another BindingSource, for Country. The
DataMember is Country, DataSource is wingFlexClientDataSet. This is the
same DataSet that is being used for the customerBindingSource that
works. wingFlexClientDataSet is a DataSet that includes the complete
Client Schema, which includes Customer, Country, and MedicalCondition.

When I then set up a Data Binding for the DataSource
FK_Customer_Country, which has the Customer.Country Foreign Key linked
to the Country.CountryID Primary Key. The DisplayMember is Country, and
the ValueMember is Country. Under (DataBindings), the SelectedValue is
customerBindingSource.

However, even with the above setup, which so far as I can tell is
correct, the combobox displays as blank. Nothing is displayed, and
nothing is selectable.

I can't think of a way to send a copy without posting the complete
solution (which I have replicated in a 1.12MB test solution) as it
doesn't involve any non IDE generated code. Even if I did post the
solution, the Database would still be missing.

Any idea what is going wrong?

Regards,
Wingot
 
S

Steven Cheng[MSFT]

Hi Wingot,

Thanks for your reply.

For the further scenario you mentioned, my understand is that you now let
the wingFlexClientDataSet return tree tables(with relations) and then bind
each of them to different dropdownlist (via setting DataMember), but found
the dropdownlist doesn't get populated,correct?

Would you confirm the following things:

** are you purely use datasource control(no extra code) for the databinding

** for the value you set to the dropdownlist's "DataTextField" and
"DataValueField" are set to the correct column field name(in the certain
table in DataSet), these columns should not be any column in other
table(linked by the original table) since ASP.NET databinding does not
support automatically linked multipe table through relation.

You can also try creating a simple aspx page and put the dropdownlist and
datasource control at top level to see whether it can works. If that also
not work, we can first concentrate on such a simplified page.

BTW, I've seen your another new thread posted. Do you think it proper that
we continue discuss here or in that one?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.






--------------------
 
S

Steven Cheng[MSFT]

Hi Wingot,

Any progress on this issue?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top