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. Advertisements

  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. Advertisements

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. piyush
    Replies:
    0
    Views:
    2,015
    piyush
    Jul 14, 2004
  2. John Black
    Replies:
    8
    Views:
    4,521
    Xenos
    Aug 20, 2004
  3. Replies:
    25
    Views:
    1,005
    MonkeeSage
    Oct 1, 2006
  4. Adam
    Replies:
    9
    Views:
    924
    red floyd
    Feb 2, 2006
  5. kj
    Replies:
    15
    Views:
    823
    Lawrence D'Oliveiro
    May 23, 2009
  6. Marteno Rodia

    catch doesn't catch a thrown exception

    Marteno Rodia, Aug 3, 2009, in forum: Java
    Replies:
    5
    Views:
    833
    Daniel Pitts
    Aug 5, 2009
  7. A
    Replies:
    8
    Views:
    1,086
    James Kanze
    Aug 28, 2010
  8. Gergely Kontra
    Replies:
    16
    Views:
    436
    Devin Mullins
    Sep 20, 2005
Loading...