Re: Populating a GridView using Combo SelectedValue and CslaDataSource in WebForm

Re: Populating a GridView using Combo SelectedValue and CslaDataSource in WebForm

Old forum URL: forums.lhotka.net/forums/t/4192.aspx


ozitraveller posted on Thursday, January 17, 2008

Hi

I thought this would be simple, but the events don't seem to fire in the order I'm expecting. Hoping some can give me a hand. I'm no web developer, yet.. Just frustrated!

What I'm trying to achieve is use a combo to filter the contents of a gridview. I can populate the combo in the page_load by setting focus to the combo which fires the SelectObject event on the DataSource.

I want to populate the gridview in combo SelectedIndexChanged event. But the SelectedIndexChanged event on the Combo doesn't fire.

If I have a SelectObject event on the GridView it fires as soon as the page loads.

Any help would be greatly appreciated.

Thanks

 

skagen00 replied on Thursday, January 17, 2008

You're talking about a dropdownlist, right?

I hate to suggest the obvious but you do have AutoPostBack=true on your DropDownList, right? (It was difficult to discern exactly what problem you were communicating.). This setting would have your page "post-back" and your event to fire allowing you to rebind your gridview.

Happy to give you more feedback if you can describe your issue a little more thoroughly...

ozitraveller replied on Thursday, January 17, 2008

Hi skagen00

I saw the AutoPostBack=true just before I saw your reply. So that's now fine.

Sorry I haven't done this before on a webpage.

What I want to do is: select a value in the combo and pass the selectedvale to the gridview datasource and rebind.

thanks

skagen00 replied on Thursday, January 17, 2008

So in your selected index changed event, one option is to simply say GridView1.DataBind() (or what have you) -- assuming you have a CslaDataSource backing the grid view, it'll nail the SelectObject once you make that call, allowing you to process the call after the selected index has changed. Your e.BusinessObject will end up being perhaps a filtered list or just a list retrieved with criteria based on the selected index.

i.e. e.BusinessObject = Inventory.GetItemsByCategoryId(value_based_on_selected_index);

Chris

 

ozitraveller replied on Thursday, January 17, 2008

Thanks Chris!

That did it...I should have got that myself.

ehonor replied on Monday, June 28, 2010

What I did to make it run,, I just bind the column name from CslaDataSource(FormView) to the Dropdownlist eg. SelectedValue='<%# Bind("Gender") %>', it will auto get the selected value of a dropdownlist.

Copyright (c) Marimer LLC