LivePersistence == False, how do I force a re-fetch to update other databound controls?

Posts   
 
    
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 19-Sep-2006 23:49:47   

Hello, I have a web user control with 2 combo boxes, and 2 LLBLGenProDataSource2 controls. Both datasource controls have their LivePersistence mode == false.

Basically, the first combo box is a list of countries. The second is a list of states. You load the countries and bind the combo. The user clicks a contry and the states combo should be re-bound.

Pretty straight forward. I cannot seem to get the StateDataSource_PerformSelect to fire again. The datasource select methods once a peice, but that seems to be it. Am I approaching this the wrong way?

Here is all the code that exists in my web user control:


protected void CountryDataSource_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
    LoadCountries(e);
}
protected void StateDataSource_PerformSelect(object sender, PerformSelectEventArgs2 e)
{
    LoadStates(e);
}
protected void CountryCombo_SelectedIndexChanged(object sender, EventArgs e)
{
    // why wont the StatesDataSource do the select again?
    StateDataSource.Select();
    StateDataSource.DataBind();
}

private void LoadCountries(PerformSelectEventArgs2 e)
{
    EntityCollectionNonGeneric countryData = (EntityCollectionNonGeneric)e.ContainedCollection;
    MyCountryRegionEntity.FetchAllCountries(ref countryData);
}
private void LoadStates(PerformSelectEventArgs2 e)
{
    if (CountryCombo.SelectedItem != null &&
                string.IsNullOrEmpty(CountryCombo.SelectedValue) == false)
    {
        EntityCollectionNonGeneric stateData = (EntityCollectionNonGeneric)e.ContainedCollection;
        MyStateProvinceEntity.FetchStatesByRegion(ref stateData,
            CountryCombo.SelectedValue);
    }
}


EDIT: prior to LLBLgen2 and databinding I would just manually fetch the states collection again, should I be taking the same approach?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Sep-2006 08:17:34   

Have you used SelectParamteres?

Would you please post the declarative html/xml code of your datasource?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Sep-2006 09:46:18   

Don't rebind in the code behind. ASP.NET 2.0 doesn't work that way.

A bound control (here a combobox) is connected with its datasource when the page is created and the bound control then asks the datasource control for the data. The datasource delivers the data and the data is then loaded into the bound control.

When you change the country selected value, you should get a postback. As walaa suggested, you should use a SelectParameter in the state datasourcecontrol which selects the selected value from the country, which then makes the combobox get different values.

Also check if you have enableviewstate set to true. This sometimes prevents controls from requesting data from the datasourcecontrols, so they'll never see changed data.

Frans Bouma | Lead developer LLBLGen Pro
Devildog74
User
Posts: 719
Joined: 04-Feb-2004
# Posted on: 20-Sep-2006 15:08:09   

ViewState had been turned off on the StateCombo when making the original post.

I added a SelectParameter to the StatesBindingSource and things worked.

<SelectParameters> <asp:ControlParameter ControlID="CountryCombo" Name="CountryCode" PropertyName="SelectedValue" Type="String" /> </SelectParameters>