Poste the code?
Set the dropdown to autopostback and add event to onselectedindexchanged and use the selected index to dig out the value, that's the most reliable approach
for example:
Web page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Dropdown dynamics sample</title>
</head>
<body>
<form id="DemoForm" runat="server">
<div>
<asp:DropDownList id="CustomerSelect" runat="server" AutoPostBack="true"
onselectedindexchanged="CustomerSelect_SelectedIndexChanged">
<asp:ListItem Value="0">Please select</asp:ListItem>
</asp:DropDownList>
<label id="CustomerActive" runat="server"></label>
</div>
</form>
</body>
</html>
and code behind
public partial class DropDownSample : System.Web.UI.Page
{
protected struct CustomerData
{
public int CustomerID;
public string Name;
public string StreetAndNumber;
}
private Dictionary<int, CustomerData> _dictionary = new Dictionary<int, CustomerData>();
protected void Page_Init(object sender, EventArgs e){
_dictionary.Add(1, new CustomerData { CustomerID = 1, Name = "Bill Spectre", StreetAndNumber = "Looneystreet 1" });
_dictionary.Add(2, new CustomerData { CustomerID = 2, Name = "Charlie P", StreetAndNumber = "Yazzlane 2" });
_dictionary.Add(3, new CustomerData { CustomerID = 3, Name = "Dick Di Spenser", StreetAndNumber = "Whatyerroad 3" });
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
foreach (var customer in _dictionary)
{
CustomerSelect.Items.Add(new ListItem(customer.Value.Name, customer.Value.CustomerID.ToString()));
}
}
}
protected void CustomerSelect_SelectedIndexChanged(object sender, EventArgs e)
{
int idx = CustomerSelect.SelectedIndex;
if (idx == 0)
{
CustomerActive.InnerText = "Please select from dropdown, one of the names";
return;
}
var cust = _dictionary[idx];
CustomerActive.InnerText = cust.StreetAndNumber;
}
}