By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

asp:dropdownlist , Only Selects first Value Problem

P: n/a
Hi,

Just seeing if anyone can help me with a problem I am having with drop
down lists.

- I have a asp:dropdownlist that gets its values from a database.
- The user then selects a value then presses the submit button.
- The submit button then calls a function that sets a asp:lable to
that value selected.
- PROBLEM: No matter what value the user selects, the asp:lable always
sets to the first value in the dropdown box!

I am guessing the problem is that on PostBack the data is binding
again and that is when the value is being written to the lable.
(That's my beginners diagnosis so it is probaly tottally wrong!)

Any help as always, appriciated.
Thanks
H

p.s. - Am using SQL (MSDE) + Dreamweaver MX.
***** Extract(c#) *****
<script runat="server">
void ShowResult(Object Sender, EventArgs e) {
if (IsPostBack);
string ethtext = ddlEthnic.SelectedItem.Value;
lblethnic.Text = ethtext;
}
</script>

<asp:dropdownlist ID="ddlEthnic" runat="server"
DataSource="<%# dsEthnic.DefaultView %>"
DataValueField="ethnic_group">
</asp:dropdownlist>

<asp:label ID="lblethnic" runat="server"></asp:label>

<asp:button ID="btnSubmit"
OnClick="ShowResult" runat="server" Text="Search Records" />

**********************
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
are you filling dropdownlistbox at page load If yes then
Put the code in

if not isPostBack then
FillDropDownListBox
end if

Hope it will must work. because your Fill is not in the defined code. When
you press the button and the button is postback then the DropdownListbox
again fill first and give you the first value.

above code will protect to fill again..

Regards
Ather Ali Shaikh
"Harry" <ha************@hotmail.com> wrote in message
news:1c**************************@posting.google.c om...
Hi,

Just seeing if anyone can help me with a problem I am having with drop
down lists.

- I have a asp:dropdownlist that gets its values from a database.
- The user then selects a value then presses the submit button.
- The submit button then calls a function that sets a asp:lable to
that value selected.
- PROBLEM: No matter what value the user selects, the asp:lable always
sets to the first value in the dropdown box!

I am guessing the problem is that on PostBack the data is binding
again and that is when the value is being written to the lable.
(That's my beginners diagnosis so it is probaly tottally wrong!)

Any help as always, appriciated.
Thanks
H

p.s. - Am using SQL (MSDE) + Dreamweaver MX.
***** Extract(c#) *****
<script runat="server">
void ShowResult(Object Sender, EventArgs e) {
if (IsPostBack);
string ethtext = ddlEthnic.SelectedItem.Value;
lblethnic.Text = ethtext;
}
</script>

<asp:dropdownlist ID="ddlEthnic" runat="server"
DataSource="<%# dsEthnic.DefaultView %>"
DataValueField="ethnic_group">
</asp:dropdownlist>

<asp:label ID="lblethnic" runat="server"></asp:label>

<asp:button ID="btnSubmit"
OnClick="ShowResult" runat="server" Text="Search Records" />

**********************

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.