painfully ignorant but frustrating

Discussion in 'ASP .Net' started by dan m, Feb 6, 2004.

  1. dan m

    dan m Guest

    I HAVE looked around but cant figure out the stupid mistake I'm
    making. I am POSTing a form and in the CodeBehind function for the
    submit i am simply building a SQL statement, however, I cant seem to
    retrieve the correct (newly selected) values for the dropdownlist
    controls. I'm sorry, i know this is elementary but I just cant see my
    error - anyone give me the lowdown?!

    SQL string below: (Im trying both the selected item & index but both
    give the original value when first rendered)...

    INSERT INTO Team " +
    "(TeamName, Email, fkManufacturerId," +
    "fkDriver1Id, fkDriver2Id, fkDriver3Id," +
    "fkTyreId,Paid) " +
    " VALUES " +
    "('" + txtTeamName.Text + "'," +
    "'" + txtUserId.Text + "'," +
    ddlManufacturer.SelectedIndex + "," +
    ddlDriver1.SelectedItem.Value + "," +
    ddlDriver2.SelectedItem.Value + "," +
    ddlDriver3.SelectedItem.Text + "," +
    ddlTyre.SelectedItem.Value + "," +
    "False);";

    cheers, dan
     
    dan m, Feb 6, 2004
    #1
    1. Advertising

  2. dan m

    Corey O'Mara Guest

    Perhaps your dropdownlists are being re-initialized on page_load and
    therefore resetting the .SelectedItem property? Remember to populate your
    dropdowns inside a "If Not Page.IsPostBack" statement. If this is not the
    case, page_load will fire before your event handler and cause the dropdowns
    to repopulate and your SelectedItem won't be set properly.

    Corey O'Mara
    MCSD.NET, MCT


    "dan m" <> wrote in message
    news:...
    > I HAVE looked around but cant figure out the stupid mistake I'm
    > making. I am POSTing a form and in the CodeBehind function for the
    > submit i am simply building a SQL statement, however, I cant seem to
    > retrieve the correct (newly selected) values for the dropdownlist
    > controls. I'm sorry, i know this is elementary but I just cant see my
    > error - anyone give me the lowdown?!
    >
    > SQL string below: (Im trying both the selected item & index but both
    > give the original value when first rendered)...
    >
    > INSERT INTO Team " +
    > "(TeamName, Email, fkManufacturerId," +
    > "fkDriver1Id, fkDriver2Id, fkDriver3Id," +
    > "fkTyreId,Paid) " +
    > " VALUES " +
    > "('" + txtTeamName.Text + "'," +
    > "'" + txtUserId.Text + "'," +
    > ddlManufacturer.SelectedIndex + "," +
    > ddlDriver1.SelectedItem.Value + "," +
    > ddlDriver2.SelectedItem.Value + "," +
    > ddlDriver3.SelectedItem.Text + "," +
    > ddlTyre.SelectedItem.Value + "," +
    > "False);";
    >
    > cheers, dan
     
    Corey O'Mara, Feb 7, 2004
    #2
    1. Advertising

  3. dan m

    dan m Guest

    THANKYOU Corey! - Perfect answer and as i said, a real simple
    (obvious) mistake which i just couldnt see!

    Kind regards, dan
     
    dan m, Feb 7, 2004
    #3
  4. Your post went unanswered. Have you resolved this issue?

    --
    Regards,
    Alvin Bruney [ASP.NET MVP]
    Got tidbits? Get it here...
    http://tinyurl.com/3he3b
    "dan m" <> wrote in message
    news:...
    > I HAVE looked around but cant figure out the stupid mistake I'm
    > making. I am POSTing a form and in the CodeBehind function for the
    > submit i am simply building a SQL statement, however, I cant seem to
    > retrieve the correct (newly selected) values for the dropdownlist
    > controls. I'm sorry, i know this is elementary but I just cant see my
    > error - anyone give me the lowdown?!
    >
    > SQL string below: (Im trying both the selected item & index but both
    > give the original value when first rendered)...
    >
    > INSERT INTO Team " +
    > "(TeamName, Email, fkManufacturerId," +
    > "fkDriver1Id, fkDriver2Id, fkDriver3Id," +
    > "fkTyreId,Paid) " +
    > " VALUES " +
    > "('" + txtTeamName.Text + "'," +
    > "'" + txtUserId.Text + "'," +
    > ddlManufacturer.SelectedIndex + "," +
    > ddlDriver1.SelectedItem.Value + "," +
    > ddlDriver2.SelectedItem.Value + "," +
    > ddlDriver3.SelectedItem.Text + "," +
    > ddlTyre.SelectedItem.Value + "," +
    > "False);";
    >
    > cheers, dan
     
    Alvin Bruney [MVP], Mar 2, 2004
    #4
    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. Mike
    Replies:
    4
    Views:
    377
  2. Rut

    xml ignorant

    Rut, Nov 19, 2004, in forum: XML
    Replies:
    3
    Views:
    437
    cr88192
    Nov 20, 2004
  3. David Lozzi
    Replies:
    4
    Views:
    408
    David Lozzi
    Jul 26, 2007
  4. ignorant question

    , Oct 2, 2004, in forum: Javascript
    Replies:
    8
    Views:
    107
  5. Debo
    Replies:
    8
    Views:
    122
Loading...

Share This Page