473,466 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Bound Dropdown List - doens't allow for user input?

Is there a way that a bound ddl control can:

1. display the bound data, even if it does not match a selection in
the DDL?
2. allow the user to enter something other than the look up values?

I have a bound dropdown list that retrieves it's selections from a
look-up table. The DDL is bound to a database table and unless the
value in the (text) field matches one of the look-up values, the page
craps out.

Thank you, Luis.

Mar 16 '07 #1
6 3916
On Mar 16, 2:52 pm, "blouie" <lrblo...@gmail.comwrote:
Is there a way that a bound ddl control can:

1. display the bound data, even if it does not match a selection in
the DDL?
Depends on your need, if it's just a search by the string

Your query to the table can be following:

string sql = "...from table where col1 LIKE '%" + ddl.SelectedValue +
"%'";

2. allow the user to enter something other than the look up values?
You will need another TextBox Control

Mar 16 '07 #2
Thanks Alexey,

For #1, I mean if there is a ddl property that allows the ddl to show
an item that is not a member of the look-up table.

For example, to show "NULL" values, I use the property
AppendDateBoundItems="True" along with <asp:ListItem Value=""></
asp:ListItemand it lets me have NULLS in the database w/o craping
out the page because the look-up table doesn't match the "NULL"
values.

I need the same type of solution but for items in the db that there is
no cooresponding item in the look-up table in my DataSourceID for the
ddl.
<asp:DropDownList AppendDataBoundItems="true" SelectedValue='<
%#Bind("II_InsuranceType") %>' ID="ddlInsuranceType_ET" runat="server"
DataSourceID="sdsInsuranceType" DataTextField="InsuranceType"
DataValueField="InsuranceType" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>

On Mar 16, 10:01 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
On Mar 16, 2:52 pm, "blouie" <lrblo...@gmail.comwrote:
Is there a way that a bound ddl control can:
1. display the bound data, even if it does not match a selection in
the DDL?

Depends on your need, if it's just a search by the string

Your query to the table can be following:

string sql = "...from table where col1 LIKE '%" + ddl.SelectedValue +
"%'";
2. allow the user to enter something other than the look up values?

You will need another TextBox Control

Mar 16 '07 #3
On Mar 16, 4:42 pm, "blouie" <lrblo...@gmail.comwrote:
I need the same type of solution but for items in the db that there is
no cooresponding item in the look-up table in my DataSourceID for the
ddl.
Can you give us an example of your data in the InsuranceType field of
your table and a final list (lookup table + ...) you would like to get?

Mar 16 '07 #4
Thanks Alexey,

I hope this is what you are looking for:

The SQL Data Source populating the "ddlInsuranceType_ET" is called
"sdsInsuranceType"
It contains the following look up records:
- InsTypeID, InsuranceType (FIELD NAMES)
- 1, "Medicare"
- 2, "MedicAID"

Therefore, the ddl shows Medicare and MedicAID

Now my customer record contins:
- CustID, CustName, II_InsuranceType (FIELD NAMES)
- 1, "Luis", "IBC"
- 2, "Alexey", "MedicAID"

Now, when look the record for Customer "Alexey", the "Selected Value"
of the ddl show "MedicAID". HOWEVER, when I look at the Customer
"Luis" record, the page craps out because "IBC" is not a valid item in
the ddl.
<asp:DropDownList AppendDataBoundItems="true" SelectedValue='<
%#Bind("II_InsuranceType") %>' ID="ddlInsuranceType_ET"
runat="server"
DataSourceID="sdsInsuranceType" DataTextField="InsuranceType"
DataValueField="InsuranceType" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>

Hope that helps,

Luis.
On Mar 16, 11:58 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
On Mar 16, 4:42 pm, "blouie" <lrblo...@gmail.comwrote:
I need the same type of solution but for items in the db that there is
no cooresponding item in the look-up table in my DataSourceID for the
ddl.

Can you give us an example of your data in the InsuranceType field of
your table and a final list (lookup table + ...) you would like to get?

Mar 16 '07 #5
On Mar 16, 6:27 pm, "blouie" <lrblo...@gmail.comwrote:
Thanks Alexey,

I hope this is what you are looking for:

The SQL Data Source populating the "ddlInsuranceType_ET" is called
"sdsInsuranceType"
It contains the following look up records:
- InsTypeID, InsuranceType (FIELD NAMES)
- 1, "Medicare"
- 2, "MedicAID"

Therefore, the ddl shows Medicare and MedicAID

Now my customer record contins:
- CustID, CustName, II_InsuranceType (FIELD NAMES)
- 1, "Luis", "IBC"
- 2, "Alexey", "MedicAID"

Now, when look the record for Customer "Alexey", the "Selected Value"
of the ddl show "MedicAID". HOWEVER, when I look at the Customer
"Luis" record, the page craps out because "IBC" is not a valid item in
the ddl.

<asp:DropDownList AppendDataBoundItems="true" SelectedValue='<
%#Bind("II_InsuranceType") %>' ID="ddlInsuranceType_ET"
runat="server"
DataSourceID="sdsInsuranceType" DataTextField="InsuranceType"
DataValueField="InsuranceType" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>

Hope that helps,

Luis.

On Mar 16, 11:58 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
On Mar 16, 4:42 pm, "blouie" <lrblo...@gmail.comwrote:
I need the same type of solution but for items in the db that there is
no cooresponding item in the look-up table in my DataSourceID for the
ddl.
Can you give us an example of your data in the InsuranceType field of
your table and a final list (lookup table + ...) you would like to get?- Hide quoted text -

- Show quoted text -
Okay, I got it! The only question is what do you want to do with that
InsuranceType, which does not exist. The

ddlInsuranceType_ET contains a key (which we don't have) and its
value.

1) SQL way.

Use a stored procedure to get the data.
I suppose, the sdsInsuranceType has something like this:

"SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType"

If you have a stored procedure (or maybe you have one already), you
can return @InsuranceType if it doesn't exist.
Here's the code you can use

CREATE PROCEDURE [dbo].[GetInsuranceType]
(
@InsuranceType varchar(100)
)
AS
BEGIN

IF EXISTS(SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType)
SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType
ELSE
SELECT -1, @InsuranceType

END
GO

You can call this procedure from your code as

"GetInsuranceType @InsuranceType"

In case of Luis/IBC it returns -1, IBC.

Here you have to think regarding the "-1" as I don't know what you
wanted to do with that key - it doesn't exist in the

database table.

2) Code-behind way.

string lookFor = "IBC";
DataSet ds = ... get a data set ... WHERE InsuranceType='" + lookFor
+"'";

if (ds.Tables[0].Rows.Count 0)
{
ddlInsuranceType_ET.DataSource = ds;
ddlInsuranceType_ET.DataBind();
} else { // for Luis/IBC
ddlInsuranceType_ET.Items.Clear();
ddlInsuranceType_ET.Items.Add(new ListItem(lookFor, "-1"));
}

or something like this

Mar 16 '07 #6
Alexey,

Thank you for such a comprehensive response.

I'm going to apply your stored procedure logic to a few of my drop-
downs. My application is full of drop downs and it would be nuts to
do it for all of them. This should be something that is
straightforward.

The reason it's such a big issue for me is that my new application is
a merger of three completely separate but related systems. Where
related data was stored in different ways. What I didn't want to do
is populate my drop downs with "similar" selections when they should
all be consolidated. At the same time, there are so many drop downs
that to go through the data and try to consolidate in the main data
itself (not look up data) would be a monumental task that the app
users are certainly not willing to do on their own. We have data
ownership issues! Therefore, the burden falls on the little ol'
developer!!!

Thanks again!
On Mar 16, 2:24 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Mar 16, 6:27 pm, "blouie" <lrblo...@gmail.comwrote:


Thanks Alexey,
I hope this is what you are looking for:
The SQL Data Source populating the "ddlInsuranceType_ET" is called
"sdsInsuranceType"
It contains the following look up records:
- InsTypeID, InsuranceType (FIELD NAMES)
- 1, "Medicare"
- 2, "MedicAID"
Therefore, the ddl shows Medicare and MedicAID
Now my customer record contins:
- CustID, CustName, II_InsuranceType (FIELD NAMES)
- 1, "Luis", "IBC"
- 2, "Alexey", "MedicAID"
Now, when look the record for Customer "Alexey", the "Selected Value"
of the ddl show "MedicAID". HOWEVER, when I look at the Customer
"Luis" record, the page craps out because "IBC" is not a valid item in
the ddl.
<asp:DropDownList AppendDataBoundItems="true" SelectedValue='<
%#Bind("II_InsuranceType") %>' ID="ddlInsuranceType_ET"
runat="server"
DataSourceID="sdsInsuranceType" DataTextField="InsuranceType"
DataValueField="InsuranceType" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>
Hope that helps,
Luis.
On Mar 16, 11:58 am, "Alexey Smirnov" <alexey.smir...@gmail.com>
wrote:
On Mar 16, 4:42 pm, "blouie" <lrblo...@gmail.comwrote:
I need the same type of solution but for items in the db that there is
no cooresponding item in the look-up table in my DataSourceID for the
ddl.
Can you give us an example of your data in the InsuranceType field of
your table and a final list (lookup table + ...) you would like to get?- Hide quoted text -
- Show quoted text -

Okay, I got it! The only question is what do you want to do with that
InsuranceType, which does not exist. The

ddlInsuranceType_ET contains a key (which we don't have) and its
value.

1) SQL way.

Use a stored procedure to get the data.
I suppose, the sdsInsuranceType has something like this:

"SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType"

If you have a stored procedure (or maybe you have one already), you
can return @InsuranceType if it doesn't exist.
Here's the code you can use

CREATE PROCEDURE [dbo].[GetInsuranceType]
(
@InsuranceType varchar(100)
)
AS
BEGIN

IF EXISTS(SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType)
SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType
ELSE
SELECT -1, @InsuranceType

END
GO

You can call this procedure from your code as

"GetInsuranceType @InsuranceType"

In case of Luis/IBC it returns -1, IBC.

Here you have to think regarding the "-1" as I don't know what you
wanted to do with that key - it doesn't exist in the

database table.

2) Code-behind way.

string lookFor = "IBC";
DataSet ds = ... get a data set ... WHERE InsuranceType='" + lookFor
+"'";

if (ds.Tables[0].Rows.Count 0)
{
ddlInsuranceType_ET.DataSource = ds;
ddlInsuranceType_ET.DataBind();} else { // for Luis/IBC

ddlInsuranceType_ET.Items.Clear();
ddlInsuranceType_ET.Items.Add(new ListItem(lookFor, "-1"));

}

or something like this- Hide quoted text -

- Show quoted text -

Mar 29 '07 #7

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

Similar topics

2
by: Jas | last post by:
I want an ASP page with a dropdown and a simple button. Every time the user chooses an item from the dropdown and clicks on the button i want that value written below in list and allow user to...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
3
by: Developerforum | last post by:
Hi, My customer is looking for a web control that allow them to perform speedy data entry. They wanted a dropdown list box which they can also key in the code directly (like a text box). I...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
4
by: Dica | last post by:
i've got a dropdown list with various options added to it. i want to add a button that allows the user to "Add New Option' which should create a blank row on the dropdown list and allow the user to...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
2
by: bdbeames | last post by:
Ok, It has been one of those days. Here is my bump in the road. I have an add user form for the administrator. The administrator enters name, password and then selects access level from a...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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,...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.