else or catch

Discussion in 'ASP .Net' started by JohnE, Jun 25, 2010.

  1. JohnE

    JohnE Guest

    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
    JohnE, Jun 25, 2010
    #1
    1. Advertising

  2. JohnE

    Mr. Arnold Guest

    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
    Mr. Arnold, Jun 26, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Black
    Replies:
    8
    Views:
    4,132
    Xenos
    Aug 20, 2004
  2. Replies:
    25
    Views:
    643
    MonkeeSage
    Oct 1, 2006
  3. kj
    Replies:
    15
    Views:
    534
    Lawrence D'Oliveiro
    May 23, 2009
  4. A
    Replies:
    8
    Views:
    774
    James Kanze
    Aug 28, 2010
  5. Gergely Kontra
    Replies:
    16
    Views:
    213
    Devin Mullins
    Sep 20, 2005
Loading...

Share This Page