0
votes

Am using DropDownList controls in ASP.NET binding values from SQL table. Some control have only one value, some control have more than one value. The SelectedIndexChanged event is not fired which control have only one value.

I set AutoPostBack=true and 0th item as select. Even though that event is not fired for that control?

2

2 Answers

1
votes

SelectedIndxChanged event fires only if you change your selection and your DDL has AUTOPOSTBACK true.

If you have only one value in DDL then you don't need this event , you can write your desire code after you bind the dropdown on server side itself.

If you are not binding DDL from server side you can write your code on or after Page_Load event there you'll get the selected index

0
votes

SelectedIndexChanged only fires when the selection has changed. If there's only one item in the dropdown list, you can never get this to fire (there's nothing to change to).

That being said, you can add a blank item to the top of the list (index 0), with the following at the top of the code where you populate the dropdown list:

MyDDList.Items.Add("");

That way you CAN choose something even with your one item.