H
Harry
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" />
**********************
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" />
**********************