views:

44

answers:

1

Hi, I have custom objects I am binding to using ObjectDataSource. I have three-level binding: a DropDownList (Department) that filters the next DropDownList (Category) that filters a GridView (Questions). Each ObjectDataSource binds to the previous control's SelectedValue (except the first one, of course).

Everything works fine only to the next level (Department to Category and Category to Questions). When I change the Department, the Category list gets updated correctly, but the Questions that show up are from the previously selected category.

How can I get this three-level binding to work correctly? I can't figure out whether I am missing something. If I have to, I could implement SelectedIndexChanged on the first list and manually force the update on the grid, but this is not ideal. Thanks for your help!

A bit more info: I don't have a default "select an item" option. That means that when I change the Department, the first Category is automatically selected. I was hoping the binding would be smart enough to trickle that all the way down. It was smart enough that I didn't have to do the if (!IsPostBack) { // Load data }.

I currently have implemented Department_SelectedIndexChanged() and simply done a Questions.DataSource = Questions.DataSource;. That seems to "refresh" everything properly. Is there a better way to do this?

+1  A: 

Hey,

Could you clear the grid instead until the second value is refreshed? Are you looking for an AjAX appraoch, or does this use postbacks?

There isn't an automatic solution that I'm aware of so you would need to do something like you mentioned because how else would the page know to refresh the grid?

Brian
How would I "clear" the grid since it's databound? And I'm using postbacks. See "A bit more info" above as well. Thanks!
Nelson
Hey, grid.DataSource = null; grid.DataBind() does the trick. You ahve to have !Page.IsPostBack code, or at least on every postback check the status of the drop downs.
Brian
I tried doing DataSource=null, DataBind(), but then it was always one step behind. DataSource=DataSource did the trick, though at the moment I can't explain why. Anyway, thanks for your help.
Nelson
at what point do you bind, load or prerender? Maybe that has something to do with it... datasource = null works for me with no issues.
Brian
Oh, the one thing... the issue with setting the data source is the ODS connected to it via the datasourceID, so that could be the issue too. Forgot about all that.
Brian