dropdown list does not change selected item?

S

SSP

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
 
A

Ashish Bhonkiya

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!"> said:
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
 
S

SSP

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 said:
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!"> said:
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 said:
<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


.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top