Trapping SelectedValue Exception on dd

R

randy.buchholz

I am trying to trap the following error. I have tried to catch it on page
load and every event on the data source and dd. No luck.
I'm forcing the error by setting the dd.text to an invalid value on page
load which seems to be when the exception is thrown. How can I trap it?
Thanks.

Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a
SelectedValue which is invalid because it does not exist in the list of
items.
Parameter name: value

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Certification"
DataValueField="Certification" Width="200px">

</asp:DropDownList>


<asp:Label ID="lbl_Error" runat="server" Text="Label"></asp:Label>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ToteConnection %>"

SelectCommand="SELECT [Certification] FROM [CertTypes]">

</asp:SqlDataSource>

protected void Page_Load(object sender, EventArgs e)
{
try
{
DropDownList1.Text = "hello";
}
catch (ArgumentOutOfRangeException ar)
{
lbl_Error.Text = ar.Message;
}

catch (Exception ex)
{
lbl_Error.Text = ex.Message;
}
}


protected void SqlDataSource1_Event??(object sender, EventArgs e)
{
try
{
DropDownList1.Text = "hello";
}
catch (ArgumentOutOfRangeException ar)
{
lbl_Error.Text = ar.Message;
}

catch (Exception ex)
{
lbl_Error.Text = ex.Message;
}
}


protected void SqlDataSource1_Event??(object sender, EventArgs e)
{
try
{
DropDownList1.Text = "hello";
}
catch (ArgumentOutOfRangeException ar)
{
lbl_Error.Text = ar.Message;
}

catch (Exception ex)
{
lbl_Error.Text = ex.Message;
}
}
 

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

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top