Master-Detail data lookup in drop down list

Posts   
 
    
colincsb
User
Posts: 18
Joined: 01-Nov-2006
# Posted on: 01-Nov-2006 19:51:15   

I am using LLBLGen Pro 2.0, .Net 2.0 and the selfservicing model.

I have two classes : DataList & DataListEntries (yeah .. should have been called DataListEntry).

DataList contains a collection of DataListEntries in a field called DataListEntries.

What I have implemented at the moment is:

1) A master DropDownList (ID = ListNamesDDL) that is bound to a LLBLGenProDataSource (ID = DataListDS) containing a DataListEntityCollection, and

2) A details ListBox (ID = ListEntriesListBox) bound to a second LLBLGenProDataSource (ID = DataListEntriesDS) that specifies the ListNamesDDL as a parameter in its SelectParameters.

Here is the code:

    <p>
        <%-- Create a new list by name --%>
        <asp:TextBox ID="TextBoxListName" runat="server"></asp:TextBox>
        <asp:Button ID="ButtonCreateList" runat="server" Text="Create List" OnClick="ButtonCreateList_Click" />
        <br />
    </p>
    <p>
        <%-- Display/Delete existing lists --%>
        <asp:Label ID="Label2" runat="server" Text="Data Lists"></asp:Label>
        <%-- Data source for DataList drop down --%>
        <llblgenpro:LLBLGenProDataSource ID="DataListDS" runat="server" DataContainerType="EntityCollection"
            EntityCollectionTypeName="CVCheck.DB.CollectionClasses.DataListCollection, CVCheck.DB"
            CacheLocation="Session">
        </llblgenpro:LLBLGenProDataSource>
        <%-- DropDownList of DataList names --%>
        <asp:DropDownList ID="ListNamesDDL" runat="server" AutoPostBack="True" DataSourceID="DataListDS"
            DataTextField="ListName" DataValueField="DataListId" OnSelectedIndexChanged="ListNamesDDL_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:Button ID="ButtonDeleteList" runat="server" Text="Delete List" OnClick="ButtonDeleteList_Click" />
    </p>
    <p>
        <%-- Display the ListEntries defined for this list --%>
        <%-- Data source for the list box --%>
        <llblgenpro:LLBLGenProDataSource ID="DataListEntriesDS" runat="server" DataContainerType="EntityCollection"
            EntityCollectionTypeName="CVCheck.DB.CollectionClasses.DataListEntriesCollection, CVCheck.DB"
            CacheLocation="Session">
            <SelectParameters>
                <asp:ControlParameter ControlId="ListNamesDDL" Name="DataListId" PropertyName="SelectedValue"
                    Type="string" />
            </SelectParameters>
        </llblgenpro:LLBLGenProDataSource>
        <%-- List box containing DataListEntry values --%>
        <asp:ListBox ID="ListEntriesListBox" runat="server" DataSourceID="DataListEntriesDS"
            DataTextField="Value" DataValueField="EntryId"></asp:ListBox>
        <br />
    </p>
    <p>
        <%-- Add/Remove list entries --%>
        <asp:Button ID="ButtonRemove" runat="server" Text="Remove" />
        <br />
        <asp:TextBox ID="TextBoxNewItem" runat="server"></asp:TextBox>
        <asp:Button ID="ButtonAddItem" runat="server" Text="Add" OnClick="ButtonAddItem_Click" />
    </p>

The purpose of the page is to be able to create/delete DataLists and create/delete DataListEntries for the selected list.

My questions are:

  1. Creating a new DataList: The ButtonCreateList_Click calls a business method to create the new DataList. The entity is created and its instance returned. How best to update the DataListDS and rebind (?) the ListNamesDDL?

Should I force DataListDS to select the list again or can I simply add the new DataListEntity to the EntityCollection of the data source?

Or ... have I gone about this the wrong way? Should I be adding the list name to the ListNamesDDL.Items and catching some event from the DataListDS to then call my business method and create the required entity? If so, is there a way to back out or cancel the 'Items.Add' call if the business logic aborts the attempted creation?

  1. Same thing for deleting a DataList?

Thanks in advance ....

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 02-Nov-2006 07:05:36   

Either way (Insert/Delete) you should force the LLBLGenProDataSource to Refetch the data.

A side note: you could have used a FormView for the DataListEntries (it makes the Edit/New/Delete tasks a bit easier to handle)

colincsb
User
Posts: 18
Joined: 01-Nov-2006
# Posted on: 03-Nov-2006 01:54:23   

How exactly do I do that?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Nov-2006 07:44:28   

The following is copied from the manual:

Refetch To ensure fresh data from the database. is retrieved, a flag on the LLBLGenProDataSourceControl called Refetch can be set to true, so the DefaultView will refetch the data, even if for example the page number is the same. This can be necessary if the code-behind code decides the data represented by the LLBLGenProDataSource control is invalidated and has to be refetched from the database. Be aware that if you bind a GridView to a LLBLGenProDataSource control and you've set EnableViewState on the GridView to true, it might be you won't see new data appear in the GridView, for example new entities you've added to the collection. This is caused because the bound control, the GridView, won't call ExecuteSelect on the LLBLGenProDataSource control again, so it won't re-fetch the data from the LLBLGenProDataSource control.