Specified argument was out of the range of valid values. Par

S

subdhar

I'm getting following error in asp.net application.I search the web
and couldn't find error like this can any one help me in trouble with
this error

Specified argument was out of the range of valid values.
Parameter name: U Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name: U

Source Error:


Line 120: {
Line 121: //if(val.Length > 0)
Line 122: ((ListBox)control).SelectedValue = val;
Line 123:
Line 124:


Source File: c:\inetpub\wwwroot\pplproot\careers\cfieldmapping.cs
Line: 122

Stack Trace:


[ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
Parameter name: U]
System.Web.UI.WebControls.ListControl.set_SelectedValue(String
value) +152
Careers.CFieldMapping.setValue(DataRow row) in
c:\inetpub\wwwroot\pplproot\careers\cfieldmapping.cs:122
Careers.SubmitResume.loadForm(DCandidateInfo data) in
c:\inetpub\wwwroot\pplproot\careers\submitresume.aspx.cs:130
Careers.SubmitResume.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\pplproot\careers\submitresume.aspx.cs:76
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
 
A

Alex Homer

It sounds like the value you're using does not already exist in the list of
values in the ListBox.
 
S

Scott Allen

Hi subhar:

Your ListBox control is trying to set the selected value to val, but
val does not exist as an option in the ListBox. You need to find out
why you are setting val to an illegal value, which is something we
cannot answer looking at this bit of code.

HTH,

--
Scott
http://www.OdeToCode.com/


On 30 Sep 2004 13:03:29 -0500,
 
S

Subhashish Dhar

Scott,
Below is the full code which ,where my list box is accessing the
"val" value.
//code/////

public void setValue(DataRow row)
{
String val = null;
if(row[columnName].GetType() != typeof(DBNull))
val = (string) row[columnName];
else
val = "";

if(control.GetType() == typeof(TextBox))
((TextBox)control).Text = val;
else if(control.GetType() == typeof(ListBox))
{
//if(val.Length > 0)
((ListBox)control).SelectedValue = val;


}
else if(control.GetType() == typeof(Label))
((Label)control).Text = val;
}
// code end here-------------------------
Below is the asp.net tracing
aspx.page Begin Init
aspx.page End Init 0.001449 0.001449
Unhandled Execution Error
Specified argument was out of the range of valid values.
Parameter name: U
at System.Web.UI.WebControls.ListControl.set_SelectedValue(String
value)
at Careers.CFieldMapping.setValue(DataRow row) in
c:\inetpub\wwwroot\pplproot\careers\cfieldmapping.cs:line 122
at Careers.SubmitResume.loadForm(DCandidateInfo data) in
c:\inetpub\wwwroot\pplproot\careers\submitresume.aspx.cs:line 130
at Careers.SubmitResume.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\pplproot\careers\submitresume.aspx.cs:line 76
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain() 0.161009 0.159560
 
S

Scott Allen

You might want to step through the code with the debugger and see what
is in the following line of code:
val = (string) row[columnName];

It would appear this does not return a value that is in the list.
You'll need to reconcile these differences, either by adding all
possible value for that column into the list, or restricting the
values appearing in the column with your SQL query (assuming this is
coming from a database).
 
V

vb bomb

Hi,
I am facing similar problem, but coulnt fix the bug.
I thing its not bug in our code but in .NET Framework itself.

I am using a global function to bind the dropdownlist

code
Public Sub BindComboBox(ByRef cmb As DropDownList, ByRef sql As
String)
Dim dv As DataView
dv = GetDataView(sql)
cmb.DataValueField = dv.Table.Columns(0).ColumnName
cmb.DataTextField = dv.Table.Columns(1).ColumnName
cmb.DataSource = dv
If dv.Count > 0 Then
cmb.DataBind()
End If
End Sub

I have used this sub in some other page which is working fine. Not just
that but it worked well till last monday, But its giving me errors now,
which i am not able to fix.

In debug mode, i traced down the values, and found the query (sql) what
i am passing is returning 2 rows.

I am worried about the mistifying behaviour of .NET which with same
piece of code works some times and soemtimes doest.

Gurus..., have any clue?


========================================
[email protected]=============
========================================
 
S

Scott Allen

You say the data has 2 rows, but are you sure the result also has at
least 2 columns?
 
B

Billy Bob

yes, if you absorve my code I am using dv.table.colums(0).columnname

If it didnt getch the 2 columns, in my code, the very next code would
give index out of range error, isnt it?.

But after long hours I solved it.

NOW I AM ROLLING BACK MY WORDS I SAID ABOUT .NET FRAMEWORK.

It was a small mistake(no its big), which was accidently modified by me.

after finding the grid, i was suppose to select the username with the
userid which i fetched from db.
For that instread of giving combobox.selectedvalue=datafieldvalue i gave
datatextvalue

it was something like this, i have userid and username columsn fecthed
and binded combobox

in my code to select the desired user in combobox, i gave
cmbReportsTo.SelectedValue=somevalue
somevalue should be userid (but i gave username value)

thats it.

bye





========================================
===========vbbomb at yahoo dot com=============
========================================
 
B

Billy Bob

Hi subdhar,

Is your problem resolved?
I thing the val at
Line 122: ((ListBox)control).SelectedValue = val
in your code is returning the DataTextField, it should match with the
DataValueField.

Bye
========================================
===========vbbomb at yahoo dot com=============
========================================
 
S

Subhashish Dhar

The default value is set as "U" as the default value in the database is
'U',Somehow .Net didn't like this string value "U".As I was debugging
someone code,I couldn't make out where this value is coming.Even if the
default value is set "U",It's giving under paramemter error.I trick the
code and make the code works.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top