I’m a beginner in C# and asp.net, i have a DropDownList with an item with text : "No item selected." and index 0.
I have a button Delete which obviously, deletes items from the DDL.
But i want to disable it when there’s only the "No item selected." item.
I tried this code :
protected void Page_Load(object sender, EventArgs e)
{
Button2.Enabled = false;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0)
{
Button2.Enabled = false;
}
else
{
Button2.Enabled = true;
}
}
But nothing happens when i add new items and select it. The Delete button is still disabled.
try this
It was resetting to “disabled” after postback