how to get selectedvalue of dropdown populated frm database
I have a dropdownlist box
<asp:DropDownList ID="drpAvailableColours" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" EnableViewState="true" >
</asp:DropDownList>
I am populating the database using the code---
DataSet dsColours = new DataSet();
string strColourQuery = "Select ProductName,ColourCode from ProductDet where ProductId in (select ProductId from ProductMaster where CatId = '1' and SubCatId='1' and BrandId='2' and SubBrandId='7')";
dsColours = db.GetTableDefinedDataSet(strColourQuery, "ProductColours");
if (dsColours.Tables["ProductColours"].Rows.Count > 0)
{
var query = dsColours.Tables["ProductColours"].AsEnumerable()
.GroupBy(x => x.Field<string>("ProductName").ToString())
.Select(x => x.First());
foreach (DataRow DistinctProducts in query)
{
drpAvailableColours.Items.Add(new ListItem(DistinctProducts["ProductName"].ToString(), DistinctProducts["ColourCode"].ToString()));
}
}
else
{
//postback
Label1.Text = drpAvailableColours.SelectedValue.ToString();
}
But I don't get the selected value from the dropdownlist in the label1
Also DropDownList1_SelectedIndexChanged doesn't trigger when I select from dropdownlist