From: JohnE on
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
From: Mr. Arnold on
JohnE wrote:
> 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