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:
- 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?
- Same thing for deleting a DataList?
Thanks in advance ....