471,598 Members | 1,153 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,598 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 3019
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Marc Le Roy | last post: by
1 post views Thread by tkpmep | last post: by
8 posts views Thread by sam | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.