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

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top