SelectParameters problem on loading data into a webform

Posts   
 
    
gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 18-Dec-2006 07:09:49   

Hello

I have a web form where I have two comboboxes that are filtered, like Country and State.

I am using adapter and the llblcollection. I user Select Parameters to filter the Combobox2 (state) based on the combobox 1 (country).

It works great, but when I want to EDIT a stored document I do the following to load the data into the form:


public void LoadData(int docID)
    {
        //_StateSource.SelectParameters.Clear(); <- If I uncomment this it works ok for loading the data but the Select parameter is lost

    DocEntity document = new DocEntity(docID);
        adapter.FetchEntity(document);

        StateEntity state = new StateEntity(Convert.ToInt32(document.stateID));
        adapter.FetchEntity(state);

    // Asign data to controls
        countryDropDown.SelectedValue = state.countryID.ToString();
        stateDropDown.SelectedValue = state.StateID.ToString();
        
    docNumber.Text = document.docNumber;

    // I am trying to add the parameter again after this, I am trying to see how to add it manually, but
    // I am not sure if it will fix it
        //Parameter parametro = new Parameter(
        //_StateSource.SelectParameters.Add(parametro);
    }

The problem I have is that the State combobox is reseted, like when you select the Country, so you can not see the asigned value.

I have readed some posts that asp.net controls have some bugs, but I am not sure if I am going in the right direction.

Thank you in advance.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Dec-2006 08:34:48   

Are you saying that on the edit form, the 2 comboboxes displays the relative information correctly (the selected values are properly set to the document Country and State)?

And then when you select another Country from the first comboBox, the second comboBox gets restes with the corresponding states?

If this is the case, then I think this is the normal behavior.

Did I understand the situation correctly, or am I missing anything?

gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 18-Dec-2006 16:20:36   

Sorry, I will explain my situation:

1) It is a form that has 2 comboboxes, combobox1 (country), filters combobox2 (States), it work ok when you want to create a new document, but I am using the same form to Edit the stored documents.

The problem comes when I want to EDIT a stored document, because I open the form and load the data in the comboboxes.

As the code above shows, I open the entity and asign the values to the comboboxes, I asign the Country and the State. But the State combobox doesnt keep the value, it is reseted to the first value of the list of states for that country (Like when the list has just been filtered after changing the country combobox value.

So I think that after asigning the value to the combobox1 on opening the form, it starts the SelectParameters action, so the combobox2 loses the value that I asigned from the document I want to edit.

With this situation supose you had a document stored with Country = USA and State= Texas. When you open the document you will have Country=USA and State= Alabama (Alabama is because it is the first state on the list).

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 18-Dec-2006 16:34:41   

Hello,

I think it's a problem of Page Life Cycle. When do you call the LoadData sub? Is there any other sub call after that modify your dropdownlist?

gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 18-Dec-2006 16:44:01   

I call the load data on the page Load, I have this on the code behind:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string keyValue = GetKeyValue();
            if (keyValue != null && keyValue != "")
                LoadData(Convert.ToInt32(keyValue));
        } 


private string GetKeyValue()
    {
        return Request.QueryString["Document_ID"];
    }

    private bool IsNewRecord()
    {
        string isNew = Request.QueryString["IsNew"];
        return (isNew != null && isNew != "");
    }

public void LoadData(int docID)
    {
        //_StateSource.SelectParameters.Clear(); <- If I uncomment this it works ok for loading the data but the Select parameter is lost

    DocEntity document = new DocEntity(docID);
        adapter.FetchEntity(document);

        StateEntity state = new StateEntity(Convert.ToInt32(document.stateID));
        adapter.FetchEntity(state);

    // Asign data to controls
        countryDropDown.SelectedValue = state.countryID.ToString();
        stateDropDown.SelectedValue = state.StateID.ToString();
        
    docNumber.Text = document.docNumber;

    // I am trying to add the parameter again after this, I am trying to see how to add it manually, but
    // I am not sure if it will fix it
        //Parameter parametro = new Parameter(
        //_StateSource.SelectParameters.Add(parametro);
    }
 }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 19-Dec-2006 09:09:52   

I think you should try to set the state value, in the comboBox OnDataBound or OnPrerender event.

Save the state.StateID in a hidden control or in a session variable then re-use it on one of the above events.

gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 19-Dec-2006 16:39:48   

Thank you very much for your help, I created a hidden textbox where I store the original ID of the state, and then onDataBound I asign the value as follows

 protected void StateDropDown_DataBound(object sender, EventArgs e)
    {
        if (!IsPostBack && !IsNewRecord())
        {
            stateTrabajoDropDown.SelectedValue = auxStateId.Text;
        }
    }

It is working now... llblgen is great, we are buying the licence this week, thank you very much again.

gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 19-Dec-2006 18:27:35   

Do you also use this technique when you have cascading comboboxes that are filtering one to the next?

As an example you have three comboboxes that are filtering through select parameters like:

COUNTRY>STATE>CITY

When you change the state, the COUNTRY rebinds, so it filters the STATE and perhaps the CITY.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 20-Dec-2006 11:32:45   

Yes, use one datasource control per combobox. Please see my example with three comboboxes below using northwind.: (Customer -> order -> Orderdetails which shows the productid's. Silly example but gets the point across wink )


        <llblgenpro:LLBLGenProDataSource2 ID="CustomerDataSource" runat="server"
            DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific">
        </llblgenpro:LLBLGenProDataSource2>
        <llblgenpro:LLBLGenProDataSource2 ID="OrderDataSource" runat="server"
            DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.OrdersEntityFactory, NWTest" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific">
            <SelectParameters>
                <asp:ControlParameter ControlID="CustomerDropDownList" Name="CustomerId" PropertyName="SelectedValue" Type="String"/>
            </SelectParameters>
        </llblgenpro:LLBLGenProDataSource2>
        <llblgenpro:LLBLGenProDataSource2 ID="OrderDetailsDataSource" runat="server"
            DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.OrderDetailsEntityFactory, NWTest" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific">
            <SelectParameters>
                <asp:ControlParameter ControlID="OrderDropDownList" Name="OrderId" PropertyName="SelectedValue" Type="String"/>
            </SelectParameters>
        </llblgenpro:LLBLGenProDataSource2>
        &nbsp;&nbsp;
        <br />
        <asp:DropDownList ID="CustomerDropDownList" runat="server" AutoPostBack="True" DataSourceID="CustomerDataSource"
            DataTextField="CustomerId" DataValueField="CustomerId">
        </asp:DropDownList>
        <asp:DropDownList ID="OrderDropDownList" runat="server" DataSourceID="OrderDataSource"
            DataTextField="OrderId" DataValueField="OrderId" AutoPostBack="True" EnableViewState="true">
        </asp:DropDownList>
        <asp:DropDownList ID="OrderDetailsDropDownList" runat="server" DataSourceID="OrderDetailsDataSource"
            DataTextField="ProductId" DataValueField="ProductId" AutoPostBack="True" EnableViewState="true">
        </asp:DropDownList>

Frans Bouma | Lead developer LLBLGen Pro
gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 21-Dec-2006 17:08:33   

Hello Otis

Thank you for the tip, however, with your example do you use the textboxs to keep the value of COSTUMERS?

Because when you change the ORDER combobox, the COSTUMERS rebinds, so it is reseting the value and perhaps the ORDER values are reseted too.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 21-Dec-2006 17:48:37   

Customers rebinds, but the datasourcecontrol has cached the data for you, and as nothing changed it won't refetch the data but return the previous fetched data. That's also why the selection for Customers isn't reset when you select an order and the selection of order isn't reset when you select a productid.

Frans Bouma | Lead developer LLBLGen Pro
gustavo
User
Posts: 15
Joined: 17-Nov-2006
# Posted on: 21-Dec-2006 18:04:06   

But I tryed this and the Orders data is being reseted after I change its value.

I change the Order data and then the Customer data selects the default value and changes my selected value on orders.. I used the same parameters as you but I dont know if I am doing something wrong.

The filters are working ok but I can not make the comboboxes to keep the value

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 22-Dec-2006 10:11:22   

gustavo wrote:

But I tryed this and the Orders data is being reseted after I change its value.

I change the Order data and then the Customer data selects the default value and changes my selected value on orders.. I used the same parameters as you but I dont know if I am doing something wrong.

The filters are working ok but I can not make the comboboxes to keep the value

The bug you run into has been fixed on December 1st. It can be you're using older runtime libs with the bug. Could you post the runtime library buildnr please? (right click on the ormsupportclasses dll in your webapp's bin folder in windows explorer -> Properties -> version tab, it's the version number at the top)

Frans Bouma | Lead developer LLBLGen Pro