wrexhamafc234
Programmer
Hello,
im having some problems selecting values from dropdown boxes:
Both dropdown selected values are exactly the same, they shouldnt be.
Any ideas why the code is not selecting the correct values?
im having some problems selecting values from dropdown boxes:
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<script runat="server">
protected void AddToList()
{
DropDownList1.Items.Clear();
DropDownList2.Items.Clear();
ListItem item1 = new ListItem();
ListItem item2 = new ListItem();
item1.Text = "0";
item1.Value = "0";
DropDownList1.Items.Add(item1);
DropDownList2.Items.Add(item1);
item2.Text = "1";
item2.Value = "1";
DropDownList1.Items.Add(item2);
DropDownList2.Items.Add(item2);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddToList();
}
DropDownList1.SelectedIndex = 1;
DropDownList1.DataBind();
DropDownList2.SelectedIndex = 0;
DropDownList2.DataBind();
}
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
</asp:DropDownList>
</div>
</form>
</body>
</html>
Both dropdown selected values are exactly the same, they shouldnt be.
Any ideas why the code is not selecting the correct values?