Binding problems to dropdowns

T

tshad

I have a couple of stored procedures that are being called from my Page_Load
event.

They worked before, but now they are not working.

I am getting the error:

Specified argument was out of the range of valid values. Parameter name:
value

The function called is:

*******************************************************
Sub GetExperienceLevel()
exit sub
Dim emailReader As SqlDataReader
trace.warn("inside GetExperienceLevel")
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsol")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Exec GetExperienceLevel"
Dim objCmd as New SqlCommand(CommandText,objConn)
objConn.Open()

ExperienceLevel.DataSource=objCmd.ExecuteReader
ExperienceLevel.DataTextField= "Description"
ExperienceLevel.DataValueField="ExperienceLevelID"
ExperienceLevel.databind()
ExperienceLevel.Items.Insert(0, "Select Experience Level")
ExperienceLevel.Items(0).value = 0
trace.warn("exiting GetExperienceLevel")
end sub
********************************************************

It is dying on the databind() line.

The dropdown is:

Experience:<asp:DropDownList id="ExperienceLevel" runat="server"
/></td>

The data coming back is:

ExperienceLevelID Description
----------------- ----------------
10 Less than 1
20 1-2 Years
30 2-5 Years

Why is it not binding?

Thanks,

Tom
 
T

tshad

tshad said:
I have a couple of stored procedures that are being called from my
Page_Load event.

They worked before, but now they are not working.

I am getting the error:

Specified argument was out of the range of valid values. Parameter name:
value

The function called is:

*******************************************************
Sub GetExperienceLevel()
exit sub
Dim emailReader As SqlDataReader
trace.warn("inside GetExperienceLevel")
Dim ConnectionString as String
=System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_ftsol")
Dim objConn as New SqlConnection (ConnectionString)
Dim CommandText as String = "Exec GetExperienceLevel"
Dim objCmd as New SqlCommand(CommandText,objConn)
objConn.Open()

ExperienceLevel.DataSource=objCmd.ExecuteReader
ExperienceLevel.DataTextField= "Description"
ExperienceLevel.DataValueField="ExperienceLevelID"
ExperienceLevel.databind()
ExperienceLevel.Items.Insert(0, "Select Experience Level")
ExperienceLevel.Items(0).value = 0
trace.warn("exiting GetExperienceLevel")
end sub
********************************************************

I tried to change the Stored procedure line to:

Dim CommandText as String = "Select ExperienceLevelID,Description from
ExperienceLevel order by ExperienceLevelID"

This came right from the Stored Procedure and works from Sql Query (as does
the SP).

Tom
 
T

tshad

I found out what was happening, just not why.

I had added some code before filling the dropdownlist that tried to select
the a value.

if not (PositionReader("ExperienceLevel") is DBNull.Value) then
ExperienceLevel.SelectedValue = PositionReader("ExperienceLevel")
end if

If I don't try to fill the Dropdownlist, I get the following code rendered.
******************************************************
Experience:<select name="ExperienceLevel" id="ExperienceLevel">
</select></td>
******************************************************

I am curious why my trying to fill the DDL after I do the above would cause
me a problem. I would have expected to get an error on trying to select a
non-existant value. But the error I got, was later on filling the DDL.

I don't understand why it happened that way.

Tom
 

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

Top