dropdown list not working

  • Thread starter Thread starter SSP
  • Start date Start date
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
 
No.

I did at once and, the resultant page had empty dropdown list with no
results.

SSP

Saravana said:
Are you checking for ispostback() before binding your dropdownlist.

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



SSP said:
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
 
Yep, it was a postback problem.

The same code didn't work earlier and it worked the second time around! I
swear asp.net has something against me :-)

Thanks Saravana

SSP

Saravana said:
Are you checking for ispostback() before binding your dropdownlist.

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com



SSP said:
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
 
Back
Top