Thursday, March 29, 2012

OnSelectedIndexChanged for drop down list?

When is this event fired? I assumed it would fire when I select an item from the drop down list, but the sub I wired to this event isn't executed.

I have a datagrid that I want to filter by using a drop down list containing categories to use as filters. So in my eventhandler for SelectedIndexChanged I do a select * from my_table where category = myDDL.SelectedItem.Value. (well not literally, but you get the picture)

Problem though is that nothing happens when I select something from the drop down list.

Also! My categories are bound from another db table, however besides getting categories from the db I would also like to add a default "ALL" category. How do I do this?

/RaymondHi!

Have you set the dorpdownlist's autopostback property to "True"?

Hope this helps,
Jeroen
1. if you don't want a button to fire the event, you must add the Autopostback property to the DDL tag and make it equal to "True"
2. if an item in the list is visible, and you click the DDL, choosing the same item, it will not fire
Thx, autopostback works fine.

What about adding a ListItem for the drop down list manually? An ALL item in addition to the ones collected from the db.

/Raymond
MyDDL.items.insert(0,"ALL")

the Zero puts the inserted item at the very top...just call this AFTER the DDL is fully databound
Thx, this works fine.

/Raymond

0 comments:

Post a Comment