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

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top