Help. Where to start for editting LEFT JOIN and databinding

Posts   
 
    
kdekok
User
Posts: 26
Joined: 07-Apr-2008
# Posted on: 18-Apr-2008 12:20:22   

I'm still in the evaluation process of llblgen, and want to get the most out of the llblgen functionality.

For this situation, i have NO IDEA where to start. Can someone give me some tips please?

Situation: 3 Tables: TUSer, TPermission and TPermission_User The last table simply combines the UserID and PermissionID.

I already have a users gridview and want to show a permissions gridview when a button is clicked in the usersgridviewrow for that user.

I can databind this PermissionsGridView in the clickevent to the TpermissionCollectionViaTpermissionUser member of the TUserCollection, but then i only have the actual permissions set.

Situation wanted: What i eventually need is a gridview with ALL the permissions, with a checkbox field. When this checkbox gets checked, a record has to be made in the TPermission_User table between the clicked permission and the actual user.

I have no clue how to do this, using as much as build-in functionality of llblgen as possible.

p.s. I Use the LLBLGenDataSource in selfservicemode and livepersistance=true.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Apr-2008 16:59:31   

It would be better if you attach your solution so we can see what you are trying to do.

Anyway I think you would find what you are looking for if you check the databinding web application in the examples section of the download page in our website.

kdekok
User
Posts: 26
Joined: 07-Apr-2008
# Posted on: 21-Apr-2008 12:09:08   

I looked at the databinding examples, but they do not quite what i need.

This is not a 1:m relationship with another table, but it involves three tables and two 1:m relationships.

It is not possible to attach the entire solution, but i hope i can clearify it with the following edittemplate of my formview:


    <llblgen:LLBLGenDataSource ID="UsersDataSource" runat="server" CacheLocation="Session" LivePersistence="true"
        DataContainerType="EntityCollection" EnablePaging="True" EntityCollectionTypeName="PFM.DO.CollectionClasses.TUserCollection, PFM.DO"
         OnEntityInserted ="UsersDataSource_EntityInserted" >
    </llblgen:LLBLGenDataSource>
...
<asp:FormView ID="UserDetailsFormView" runat="server" DataKeyNames="UserId" DataSourceID="UsersDataSource" DefaultMode="Edit" 
                        OnItemCommand="UserDetailsFormView_ItemCommand">

<EditItemTemplate>
                    <table>
                    <tr>
                    <td align="left">
                    <table>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label2" runat="server" Text="User ID:"/></td>
                        <td align="left" class="colorstdgreen font11px"><asp:Label ID="Label3" runat="server" Text='<%# Eval("UserId") %>'></asp:Label></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label4" runat="server" Text="User Name:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:TextBox CssClass="txtbox" ID="UserName" runat="server" Text='<%# Bind("UserName") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label5" runat="server" Text="Full Name:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:TextBox CssClass="txtbox"  ID="FullName" runat="server" Text='<%# Bind("FullName") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label7" runat="server" Text="User Level:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:TextBox CssClass="txtbox"  ID="UserLevel" runat="server" Text='<%# Bind("UserLevel") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label8" runat="server" Text="Enabled:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:CheckBox ID="EnabledCheckBox" runat="server" Checked='<%# Bind("Enabled") %>'/></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label14" runat="server" Text="E-Mail:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:TextBox CssClass="txtbox"  ID="Email" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label19" runat="server" Text="Must Activate:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:CheckBox ID="MustActivateCheckBox" runat="server" Checked='<%# Bind("MustActivate") %>' /></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label15" runat="server" Text="Valid From:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:Label ID="Label20" runat="server" Text='<%# Bind("ValidFrom") %>'></asp:Label></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorstdpink font11pxbold"><asp:Label ID="Label21" runat="server" Text="Valid Until:" /></td>
                        <td align="left" class="colorstdgreen font11px"><asp:Label ID="Label22" runat="server" Text='<%# Bind("ValidUntil") %>'></asp:Label></td>
                    </tr>
                    </table>                                
                    </td>
                    <td valign="top">
                        <asp:Image ID="UserPhoto" runat="server" AlternateText="User picture" Width="100px" Height="150px" style="border: solid 1px black;" ImageUrl='<%# "~/Logic/GetImage.aspx?PhotoID=" + Eval("PhotoID") %>'></asp:Image>
                        <br />
                        <asp:CheckBoxList ID="RolesCheckList" runat="server" DataSource='<%# Bind("TroleCollectionViaTroleUser") %>' DataValueField="RoleID" DataTextField="RoleName" ></asp:CheckBoxList>
                    </td>
                </tr>
                </table>
                <hr style="border: solid 1px black;"/>
                <table>
                    <tr>
                        <td class="font11px"><asp:Button runat="server" Text="Reset Password" ID="ResetPasswordButton" CssClass="btngreen" /></td>
                        <td class="font11px"><asp:Button ID="ChangePhotoButton" Text="Change Photo" runat="server" CssClass="btngreen" Enabled="false" /></td>
                    </tr>
                    </table>

                <table id="Table2">
                    <tr>
                        <td align="right" class="colorgray font10px"><asp:Label ID="Label10" runat="server" Text="Created By:" /></td>
                        <td align="left" class="colorstdgreen font10px"><asp:Label ID="CreateByLabel" runat="server" Text='<%# Bind("CreateBy") %>'></asp:Label></td>
                        <td align="right" class="colorgray font10px"><asp:Label ID="Label11" runat="server" Text="Created At:" /></td>
                        <td align="left" class="colorstdgreen font10px"><asp:Label ID="CreateAtLabel" runat="server" Text='<%# Bind("CreateOn") %>'></asp:Label></td>
                    </tr>
                    <tr>
                        <td align="right" class="colorgray font10px"><asp:Label ID="Label12" runat="server" Text="Edited By:" /></td>
                        <td align="left" class="colorstdgreen font10px"><asp:Label ID="EditByLabel" runat="server" Text='<%# Bind("EditBy") %>'></asp:Label></td>
                        <td align="right" class="colorgray font10px"><asp:Label ID="Label13" runat="server" Text="Edited At:" /></td>
                        <td align="left" class="colorstdgreen font10px"><asp:Label ID="EditAtLabel" runat="server" Text='<%# Bind("EditOn") %>'></asp:Label></td>
                    </tr>
                </table>
                <hr style="border: solid 1px black;" />
                <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" CssClass="btnblue" Text="Update">
                </asp:Button>
                <asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="btnblue" Text="Cancel">
                </asp:Button>
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CssClass="btnblue" Text="Delete" />
                <ajax:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server"
                    TargetControlID="DeleteButton"
                    ConfirmText="Are you sure you want to delete this record?" />
                </EditItemTemplate>
...

In the above code you can see the CheckBoxList control. I'm binding it to the 'TroleCollectionViaTroleUser'-property of the DataSource object.

This is the collection of Roles the user is in, collected via the table TRole_User, which just combines the UserID of table TUser en RoleID of table TRole since users can be in multiple roles, and roles can have multiple users.

What is does now, is displaying only the RoleNames this user is in, all unchecked. Also checking the items has no effect when i click the Update button to save changes.

What i need to accomplish is: * Have this list display ALL the available roles in the TRole table * Have all the Roles which this user is in, checked when the FormView is displayed * Have all the changes to the checked listitems, result in changes to the TRole_User table (newly checked items must be inserted, newly unchecked items must be deleted)

I might be on the wrong track here, but i'm kinda stuck and do not know how to do this...

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-Apr-2008 11:04:15   

Alright here is what you should do:

1- Use a prefetchPath with the UsersDataSource to fetch the User.UserRole collection.

2- In the Form View use a CheckBoxList which displays all Roles available.

3- Use the FormView ItemDataBound event, to manually check the Roles in the CheckBoxList according to the RoleID found in the bound User.UserRole collection.

4- For saving you would need to set LivePersistence to false and handle the PerformWork event to to modify the User.UserRole collection and save the User entity recursively.