dropdown list does not change selected item?

Discussion in 'ASP .Net Web Controls' started by SSP, Oct 29, 2003.

  1. SSP

    SSP Guest

    I have a dropdown list on my page as:

    <asp:dropdownlist id=ddJobtypes runat="server" ></asp:dropdownlist>
    <asp:button id=jobtypes_btn runat="server" Text="GO!"></asp:button>

    This is bound in the codebehind file as:

    JobTypesDD_sqlDataAdapter.Fill(dsJobTypesDD1);
    ddJobtypes.DataSource = dsJobTypesDD1;
    ddJobtypes.DataTextField = "jobClassName";
    ddJobtypes.DataValueField = "jobClassID";
    ddJobtypes.DataBind();

    When I click the button "jobtypes_btn" the following is called:

    private void jobtypes_btn_Click(object sender, System.EventArgs e)
    {
    JobtypesSearch_sqlSelectCommand.Parameters["@jobClass"].Value =
    ddJobtypes.SelectedValue.ToString();
    sqlConnection1.Open();
    JobtypesSearch_sqlSelectCommand.ExecuteNonQuery();
    JobtypesSearch_sqlDataAdapter.Fill(dsJobTypesSearch1);
    dgJobtypesSearch.DataBind();
    sqlConnection1.Close();

    vacancyText_Panel.Visible = false;
    JobTypes_Panel.Visible = true;
    }

    When I open the aspx file I get the folowing HTML code where the
    dropdownlist is:
    ....
    <select name="ddJobtypes" id="ddJobtypes">
    <option value="3">Accounting and Audit Classification</option>
    <option value="1">Dental Officer</option>
    <option value="4">Education Officers</option>
    </select><input type="submit" name="jobtypes_btn" value="GO!"
    id="jobtypes_btn" />
    ....

    When I click the jobtypes_btn button (after selecting any of the options),
    it gives me the result for option value 3 and the HTML code turns:

    <select name="ddJobtypes" id="ddJobtypes" class="formTxtBox">
    <option selected="selected" value="3">Accounting and Audit
    Classification</option>
    <option value="1">Dental Officer</option>
    <option value="4">Education Officers</option>
    </select><input type="submit" name="jobtypes_btn" value="GO!"
    id="jobtypes_btn" class="formTxtBox" />

    What am I doing wrong?

    SSP
     
    SSP, Oct 29, 2003
    #1
    1. Advertising

  2. Hey Hi There.
    i guess you are not checking for Page.IsPostBack in the
    page load event ?

    this shud be the problem

    HTH
    Regards
    Ashish Bhonkiya

    >-----Original Message-----
    >I have a dropdown list on my page as:
    >
    ><asp:dropdownlist id=ddJobtypes runat="server"
    ></asp:dropdownlist>
    ><asp:button id=jobtypes_btn runat="server"

    Text="GO!"></asp:button>
    >
    >This is bound in the codebehind file as:
    >
    > JobTypesDD_sqlDataAdapter.Fill(dsJobTypesDD1);
    > ddJobtypes.DataSource = dsJobTypesDD1;
    > ddJobtypes.DataTextField = "jobClassName";
    > ddJobtypes.DataValueField = "jobClassID";
    > ddJobtypes.DataBind();
    >
    >When I click the button "jobtypes_btn" the following is

    called:
    >
    > private void jobtypes_btn_Click(object sender,

    System.EventArgs e)
    > {
    > JobtypesSearch_sqlSelectCommand.Parameters

    ["@jobClass"].Value =
    >ddJobtypes.SelectedValue.ToString();
    > sqlConnection1.Open();
    > JobtypesSearch_sqlSelectCommand.ExecuteNonQuery();
    > JobtypesSearch_sqlDataAdapter.Fill

    (dsJobTypesSearch1);
    > dgJobtypesSearch.DataBind();
    > sqlConnection1.Close();
    >
    > vacancyText_Panel.Visible = false;
    > JobTypes_Panel.Visible = true;
    > }
    >
    >When I open the aspx file I get the folowing HTML code

    where the
    >dropdownlist is:
    >....
    ><select name="ddJobtypes" id="ddJobtypes">
    > <option value="3">Accounting and Audit

    Classification</option>
    > <option value="1">Dental Officer</option>
    > <option value="4">Education Officers</option>
    > </select><input type="submit" name="jobtypes_btn"

    value="GO!"
    >id="jobtypes_btn" />
    >....
    >
    >When I click the jobtypes_btn button (after selecting any

    of the options),
    >it gives me the result for option value 3 and the HTML

    code turns:
    >
    ><select name="ddJobtypes" id="ddJobtypes"

    class="formTxtBox">
    > <option selected="selected" value="3">Accounting and

    Audit
    >Classification</option>
    > <option value="1">Dental Officer</option>
    > <option value="4">Education Officers</option>
    ></select><input type="submit" name="jobtypes_btn"

    value="GO!"
    >id="jobtypes_btn" class="formTxtBox" />
    >
    >What am I doing wrong?
    >
    >SSP
    >
    >
    >.
    >
     
    Ashish Bhonkiya, Oct 29, 2003
    #2
    1. Advertising

  3. SSP

    SSP Guest

    Ashish,

    Thanks for the reply, you're absolutely right. The problem was the
    "IsPostBack", the first time I had the same code, it didn't work. :-(

    SSP

    "Ashish Bhonkiya" <> wrote in message
    news:0ca401c39e26$2b835900$...
    > Hey Hi There.
    > i guess you are not checking for Page.IsPostBack in the
    > page load event ?
    >
    > this shud be the problem
    >
    > HTH
    > Regards
    > Ashish Bhonkiya
    >
    > >-----Original Message-----
    > >I have a dropdown list on my page as:
    > >
    > ><asp:dropdownlist id=ddJobtypes runat="server"
    > ></asp:dropdownlist>
    > ><asp:button id=jobtypes_btn runat="server"

    > Text="GO!"></asp:button>
    > >
    > >This is bound in the codebehind file as:
    > >
    > > JobTypesDD_sqlDataAdapter.Fill(dsJobTypesDD1);
    > > ddJobtypes.DataSource = dsJobTypesDD1;
    > > ddJobtypes.DataTextField = "jobClassName";
    > > ddJobtypes.DataValueField = "jobClassID";
    > > ddJobtypes.DataBind();
    > >
    > >When I click the button "jobtypes_btn" the following is

    > called:
    > >
    > > private void jobtypes_btn_Click(object sender,

    > System.EventArgs e)
    > > {
    > > JobtypesSearch_sqlSelectCommand.Parameters

    > ["@jobClass"].Value =
    > >ddJobtypes.SelectedValue.ToString();
    > > sqlConnection1.Open();
    > > JobtypesSearch_sqlSelectCommand.ExecuteNonQuery();
    > > JobtypesSearch_sqlDataAdapter.Fill

    > (dsJobTypesSearch1);
    > > dgJobtypesSearch.DataBind();
    > > sqlConnection1.Close();
    > >
    > > vacancyText_Panel.Visible = false;
    > > JobTypes_Panel.Visible = true;
    > > }
    > >
    > >When I open the aspx file I get the folowing HTML code

    > where the
    > >dropdownlist is:
    > >....
    > ><select name="ddJobtypes" id="ddJobtypes">
    > > <option value="3">Accounting and Audit

    > Classification</option>
    > > <option value="1">Dental Officer</option>
    > > <option value="4">Education Officers</option>
    > > </select><input type="submit" name="jobtypes_btn"

    > value="GO!"
    > >id="jobtypes_btn" />
    > >....
    > >
    > >When I click the jobtypes_btn button (after selecting any

    > of the options),
    > >it gives me the result for option value 3 and the HTML

    > code turns:
    > >
    > ><select name="ddJobtypes" id="ddJobtypes"

    > class="formTxtBox">
    > > <option selected="selected" value="3">Accounting and

    > Audit
    > >Classification</option>
    > > <option value="1">Dental Officer</option>
    > > <option value="4">Education Officers</option>
    > ></select><input type="submit" name="jobtypes_btn"

    > value="GO!"
    > >id="jobtypes_btn" class="formTxtBox" />
    > >
    > >What am I doing wrong?
    > >
    > >SSP
    > >
    > >
    > >.
    > >
     
    SSP, Oct 29, 2003
    #3
    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. rohith
    Replies:
    3
    Views:
    6,026
    rohith
    Aug 29, 2003
  2. Kris Rockwell

    DropDown List Default Selected Item

    Kris Rockwell, Apr 11, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    27,904
    Dan Brussee
    Apr 12, 2004
  3. =?Utf-8?B?TWVyZGFhZA==?=

    Drop down list does not see the selected item!

    =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    11,927
    =?Utf-8?B?TWVyZGFhZA==?=
    Oct 20, 2004
  4. Replies:
    6
    Views:
    613
  5. SA SA
    Replies:
    5
    Views:
    2,555
    Ray Costanzo [MVP]
    Oct 19, 2006
Loading...

Share This Page