I have the following dropdownlist:
<%@ Page Title="" Language="C#" MasterPageFile="~/myMasterPage.master" AutoEventWireup="true" CodeFile="testdropdown.aspx.cs" Inherits="testdropdown" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:DropDownList ID="ddlDeliveryAddresses" runat="server"
DataTextField="delAddressShort" DataValueField="delID"
onselecteddindexchanged="ddlDeliveryAddresses_SelectedIndexChanged"
AppendDataBoundItems="True"
AutoPostBack="True">
<asp:ListItem Selected='True' Text='--select--' Value='-1'></asp:ListItem>
</asp:DropDownList>
</asp:Content>
And this code behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
conn = new SqlConnection(iceConns.iconn);
comm = new SqlCommand("Customers.sl_DeliverybyBillID", conn);
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.Add(new SqlParameter("@billID", SqlDbType.Int));
comm.Parameters["@billID"].Value = 160;
conn.Open();
reader = comm.ExecuteReader();
ddlDeliveryAddresses.DataSource = reader;
ddlDeliveryAddresses.DataBind();
reader.Close();
}
}
protected void ddlDeliveryAddresses_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text = ddlDeliveryAddresses.SelectedItem.Text;
}
No matter what I do I can’t populate the label. All works great if I replace the databind with static listitems! I’ve tried pretty much all the suggestions around, but nothing works (well not for me anyway!).
Your code says
onselecteddindexchanged, it should beOnSelectedIndexChanged.The casing should not matter, but notice the extra “d” after
onselected...