473,770 Members | 5,136 Online
Bytes | Software Development & Data Engineering Community
+ 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 3933
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.SelectedVal ue +
"%'";

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
AppendDateBound Items="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:DropDownLi st AppendDataBound Items="true" SelectedValue=' <
%#Bind("II_Insu ranceType") %>' ID="ddlInsuranc eType_ET" runat="server"
DataSourceID="s dsInsuranceType " DataTextField=" InsuranceType"
DataValueField= "InsuranceT ype" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownLis t>

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.SelectedVal ue +
"%'";
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 "ddlInsuranceTy pe_ET" is called
"sdsInsuranceTy pe"
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_InsuranceTyp e (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:DropDownLi st AppendDataBound Items="true" SelectedValue=' <
%#Bind("II_Insu ranceType") %>' ID="ddlInsuranc eType_ET"
runat="server"
DataSourceID="s dsInsuranceType " DataTextField=" InsuranceType"
DataValueField= "InsuranceT ype" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownLis t>

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 "ddlInsuranceTy pe_ET" is called
"sdsInsuranceTy pe"
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_InsuranceTyp e (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:DropDownLi st AppendDataBound Items="true" SelectedValue=' <
%#Bind("II_Insu ranceType") %>' ID="ddlInsuranc eType_ET"
runat="server"
DataSourceID="s dsInsuranceType " DataTextField=" InsuranceType"
DataValueField= "InsuranceT ype" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownLis t>

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

ddlInsuranceTyp e_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 sdsInsuranceTyp e 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].[GetInsuranceTyp e]
(
@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

"GetInsuranceTy pe @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)
{
ddlInsuranceTyp e_ET.DataSource = ds;
ddlInsuranceTyp e_ET.DataBind() ;
} else { // for Luis/IBC
ddlInsuranceTyp e_ET.Items.Clea r();
ddlInsuranceTyp e_ET.Items.Add( new ListItem(lookFo r, "-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 "ddlInsuranceTy pe_ET" is called
"sdsInsuranceTy pe"
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_InsuranceTyp e (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:DropDownLi st AppendDataBound Items="true" SelectedValue=' <
%#Bind("II_Insu ranceType") %>' ID="ddlInsuranc eType_ET"
runat="server"
DataSourceID="s dsInsuranceType " DataTextField=" InsuranceType"
DataValueField= "InsuranceT ype" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownLis t>
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

ddlInsuranceTyp e_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 sdsInsuranceTyp e 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].[GetInsuranceTyp e]
(
@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

"GetInsuranceTy pe @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)
{
ddlInsuranceTyp e_ET.DataSource = ds;
ddlInsuranceTyp e_ET.DataBind() ;} else { // for Luis/IBC

ddlInsuranceTyp e_ET.Items.Clea r();
ddlInsuranceTyp e_ET.Items.Add( new ListItem(lookFo r, "-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
9621
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 select more. Also how can these choices be saved somehow so tha when the user goes to the next page the choices he made can be written to the database. For example The choices in the dropdown may be
1
2945
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 javascript; I just don't get the syntax at all. If anyone could help, I would appreciate it. I'm probably pretty close. Please note that because it's an Intranet, all users have to use IE 5 or higher. Situation: 3 form fields on an ASP. <select>...
3
1497
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 notice that current the dropdown box allow first character search, (i.e. when user enter "P", the dropdown list box will "jump" to the first P item).
6
10697
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. Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different functionalities: 1. After pressing the back button, the item you selected in the dropdown is still selected.
4
8096
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 type directly into it. is this possible?
2
4556
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
4
2633
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 before the list is repopulated. For example, suppose the user selects 3 in the drop down list and 3 text fields are shown. If the user populates the 3 text fields with data and decides to change the drop down to a list of 4 or 5, how do I capture...
2
2188
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 dropdown. When the data is posted I take the administrator to a page where all users can be viewed. I then allow the administrator to select a user in the list that they would like to edit. The administrator is taken back to the add user form, but the...
4
4587
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 reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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
10230
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
10004
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
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
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...
0
6678
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
5313
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...
3
2817
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.