473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Default value for dropdownlist databound control

11
I have a dropdownlist databound to table column with string values "n" i "y".

<asp:DropDownList ID="ddlPrivate" runat="server" SelectedValue='<%# Bind("cPrivate") %>'>
<asp:ListItem Value="n">No</asp:ListItem>
<asp:ListItem Value="y">Yes</asp:ListItem>
</asp:DropDownList>

How to handle situation when value is not "n" or "y" to avoid exception.
Is it possible to make dropdownlist select some default value when binded value does not fall in range. (e.g. "")

Danielz
Jul 27 '07 #1
3 3151
kenobewan
4,871 Expert 4TB
Welcome to TSDN. I believe your choice is to validate it, client or server side, or to test for a null value. HTH.
Jul 28 '07 #2
radcaesar
759 Expert 512MB
Set its 'DropDownStyle' property to 'DropDownList'.
Jul 28 '07 #3
dizzy77
11
Well I wanted to make sure that if 'cPrivate' column value different than 'y' or 'n' I don't get binding exception at presentation layer. But decided that I can simply modify my sql query:
(SELECT cPrivate = CASE WHEN cPrivate = 'Y' THEN 'Y' ELSE 'N' END) AS cPrivate

This way possible wrong values in database are corrected at data layer.
Otherwise I should somehow catch binding exception (still don't know how) which would anyway require more code and effort.

Thanks
Daniel
Jul 30 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aymer | last post by:
Scenario: i have a drop down list control in my form. i am binding it with a dataset. that dataset contains the value 1, 2, 3, ..., 10. so when the dropdownlist control is loaded, it contain...
1
by: Vi | last post by:
Hi, I have a pop-up window in which I have 3 WebControls.DropDownList controls. I make my selections and when I submit the page, in the code behind page one control has the right value for...
1
by: IMB | last post by:
I'm using VS2005 and am working with a ASP.NET 2.0 web site and I'm coding in VB.NET. I understand that I can add an item to a databound dropdownlist and make it the default selection using the...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
0
by: Mark Micallef | last post by:
Hi, I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm using: <InsertItemTemplate> <div class="insertArea">...
1
by: Mark Micallef | last post by:
Hi, this question relates to a control in the Ajax toolkit for asp.net 2. I'm having a problem using a databound dropdownlist inside a reorderlist ajax control. Here's a snippet of the code I'm...
3
by: Brian VanDyke | last post by:
I have to display a table with customer data (GridView). However, I want to be able to show DropDownList controls inside one of the columns, not just textbox controls. Is this possible? Is it...
5
by: nzkks | last post by:
Hi I am using these: ASP.Net 2.0, VB.Net, Visual Studio 2005, SQL Server 2005, Formview controls In a ASP.Net form I have 20 textboxes and 20 dropdownlists(ddl). All ddl(s) are databound and get...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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,...
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...
0
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,...

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.