473,406 Members | 2,956 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,406 software developers and data experts.

DropDownList SelectedValue returning "out of the range"

Here's my function:

public void getInterestLevelDDL(string co_interest_level)
{
sql = [valid sql];

//get_select_list creates a valid ICollection datatable
ctrlDDL_CIL.DataSource = tools.get_select_list(sql);
ctrlDDL_CIL.DataTextField = "value";
ctrlDDL_CIL.DataValueField = "key";
try
{
ctrlDDL_CIL.SelectedValue = co_interest_level;
ctrlDDL_CIL.DataBind();

}
catch
{
ctrlDDL_CIL.SelectedValue = "0";
ctrlDDL_CIL.DataBind();

}

}

If co_interest_level is in the range of dropdownlist values, I've no
problems. However, sometimes it's not, but I can't seem to get the code
to return a default gracefully. This example fails on the second
DataBind() with the error "Specified argument was out of the range of
valid values. Parameter name: value". However, the value "0" is ALWAYS
in the list, as I've made it part of the get_select_list return value.
Also, I've tried a ClearSelection(), but that doesn't seem to do a thing...

I'd sure appreciate any help!

--Brent
Dec 1 '05 #1
2 3120
Hi,

I dont think DataBind() call in the catch block is required.

"Brent" <"writeBrent at the google mail p" wrote:
Here's my function:

public void getInterestLevelDDL(string co_interest_level)
{
sql = [valid sql];

//get_select_list creates a valid ICollection datatable
ctrlDDL_CIL.DataSource = tools.get_select_list(sql);
ctrlDDL_CIL.DataTextField = "value";
ctrlDDL_CIL.DataValueField = "key";
try
{
ctrlDDL_CIL.SelectedValue = co_interest_level;
ctrlDDL_CIL.DataBind();

}
catch
{
ctrlDDL_CIL.SelectedValue = "0";
ctrlDDL_CIL.DataBind();

}

}

If co_interest_level is in the range of dropdownlist values, I've no
problems. However, sometimes it's not, but I can't seem to get the code
to return a default gracefully. This example fails on the second
DataBind() with the error "Specified argument was out of the range of
valid values. Parameter name: value". However, the value "0" is ALWAYS
in the list, as I've made it part of the get_select_list return value.
Also, I've tried a ClearSelection(), but that doesn't seem to do a thing...

I'd sure appreciate any help!

--Brent

Dec 1 '05 #2
Hi,

You have the DataBind incorrectly , it should be:
try
{
ctrlDDL_CIL.DataBind();
ctrlDDL_CIL.SelectedValue = co_interest_level;
}
And remove the DataBind in the catch block
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Brent" <"writeBrent at the google mail place"> wrote in message
news:11*************@corp.supernews.com...
Here's my function:

public void getInterestLevelDDL(string co_interest_level)
{
sql = [valid sql];

//get_select_list creates a valid ICollection datatable
ctrlDDL_CIL.DataSource = tools.get_select_list(sql);
ctrlDDL_CIL.DataTextField = "value";
ctrlDDL_CIL.DataValueField = "key";
try
{
ctrlDDL_CIL.SelectedValue = co_interest_level;
ctrlDDL_CIL.DataBind();

}
catch
{
ctrlDDL_CIL.SelectedValue = "0";
ctrlDDL_CIL.DataBind();

}

}

If co_interest_level is in the range of dropdownlist values, I've no
problems. However, sometimes it's not, but I can't seem to get the code to
return a default gracefully. This example fails on the second DataBind()
with the error "Specified argument was out of the range of valid values.
Parameter name: value". However, the value "0" is ALWAYS in the list, as
I've made it part of the get_select_list return value. Also, I've tried a
ClearSelection(), but that doesn't seem to do a thing...

I'd sure appreciate any help!

--Brent

Dec 1 '05 #3

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

Similar topics

15
by: Marc Le Roy | last post by:
Hello, ADA Ravenscar is a restricted subset of the ADA language that has been defined for real-time software development in safety critical applications. Completed with additional restrictions...
3
by: Michael Conroy | last post by:
Hi... Synposis... Throws exception: "Specified argument was out of the range of valid values." Read on for the juicy tidbits. MySimpleClassCol mscc=new MySimpleClassCol(); private void...
1
by: Clark Choi | last post by:
I ran the sample application called Petstore from msdn. Everything went fine until I tested Update button on the web form to update the database through Datagrid. I have been searching the web to...
2
by: Lenonardo | last post by:
Hi. I'm writing a VB.Net application to update multiple Excel Worksheets. I'm using late binding (i.e. all variables are objects + use createobject) I develop the application on an XP...
0
by: H5N1 | last post by:
hi all it's extremely common scenario, so I would like to ask you how do you usually implement CRUD functionality for following structure. Basically it's all about displaying "foreign name" (ie....
1
by: tkpmep | last post by:
I write data to Excel files using PyExcelerator 0.6.3.a and have done so successfully for small files (10-15 cells). I'm experiencing an error when writing a big chunk of data (10,000 cells) to...
8
by: sam | last post by:
hey everybody, this is my first time posting here. i'm pretty new to python and programming in general (as you'll soon work out for yourselves...) i'm trying to code a version of a selection...
3
by: dvanderwel | last post by:
I have a .NET 1.1 web page with a DataGrid containing a TemplateColumn that contains a DropDownList. I need to fire an event when the selected item in the DropDownList changes for the current...
0
by: CoreyReynolds | last post by:
Hey all, I have a piece of code that dumps a bunch of data into a spreadsheet. Also rearranges it into a pivot table and then graphs the pivot table as well so my boss can get a clear view of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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
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...

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.