else or catch

J

JohnE

Have the following for inserting a person's name. If the user was to select
the empty space of the droplist, it will error. I was wondering if an else
or the full try...catch would be needed here? If an else is sufficient, what
is the better approach in what to use.

protected void lvwDetailDeveloperEditInsert_ItemInserting(object sender,
ListViewInsertEventArgs e)
{
DropDownList ddlDeveloperIDInsertEdit =
(DropDownList)e.Item.FindControl("ddlDeveloperIDInsertEdit");
Label ChangeRequestIDLabel =
(Label)e.Item.FindControl("ddlSelectChangeRequest");

if (ddlDeveloperIDInsertEdit != null)
{
e.Values["DeveloperID"] =
(Convert.ToInt32(ddlDeveloperIDInsertEdit.SelectedValue));
e.Values["ChangeRequestID"] =
(Convert.ToInt32(ddlSelectChangeRequest.SelectedValue));
}
}

Thanks...John
 
M

Mr. Arnold

JohnE said:
Have the following for inserting a person's name. If the user was to select
the empty space of the droplist, it will error. I was wondering if an else
or the full try...catch would be needed here? If an else is sufficient, what
is the better approach in what to use.

protected void lvwDetailDeveloperEditInsert_ItemInserting(object sender,
ListViewInsertEventArgs e)
{
DropDownList ddlDeveloperIDInsertEdit =
(DropDownList)e.Item.FindControl("ddlDeveloperIDInsertEdit");
Label ChangeRequestIDLabel =
(Label)e.Item.FindControl("ddlSelectChangeRequest");

if (ddlDeveloperIDInsertEdit != null)
{
e.Values["DeveloperID"] =
(Convert.ToInt32(ddlDeveloperIDInsertEdit.SelectedValue));
e.Values["ChangeRequestID"] =
(Convert.ToInt32(ddlSelectChangeRequest.SelectedValue));
}
}

Thanks...John

If the value is null or string.empty the just exit.

If (object == null) // or it could empty.string I guess
return; // exit the method
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top