FormView - Binding with an embedded control

Posts   
 
    
Posts: 254
Joined: 16-Nov-2006
# Posted on: 25-Feb-2007 16:29:51   

Guys,

Im having issues with binding a GridView and FormView to a single LLBGen data source control. The form view contains a Name property as a simple text box control and a user control. The user control is simple and just contains a text box and embedded list box.

I have an entity CodeTechnology which contains a collection of CodeTechnologyFileExtension objects. The FormView should be to the properties of a single CodeTechnology object. I can bind the Name property easily using ASPX such as

<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' Columns="50"/>

However I can't get the binding working from the codeTechnology.CodeTechnologyFileExtension property so it binds the embedded list box in the user control to the values of each property in the CodeTechnologyFileExtensionCollection object.

The control is declared list this

<uc1:TransferTextToList ID="transferFileExtensionsToList" SourceTextBoxCaption="" runat="server" />

I have also created properties such as TargetListDataSource on the UserControl which simply wrap the DataSource on the embedded list box however I'm not sure how to use it in the calling page ASPX or code behind.

I can bind from the control to the data source i.e. when creating new records in the form view however I can't do it the other way around to load the data into the control. i.e. the PerformWork event handler on the data source has code

            codeTechnology = uowElement[0].Entity as CodeTechnologyEntity;

            // Obtain a list of file extensions in the target list
            Controls_TransferTextBoxToListBoxControl transferFileExtensionsToList = CodeTechnologyFormView.Row.FindControl("transferFileExtensionsToList") as Controls_TransferTextBoxToListBoxControl;
            ListItemCollection targetListFileExtensions = transferFileExtensionsToList.TargetListItems;

            // Add each file extension to the CodeTechnologyEntity object
            foreach (ListItem fileExtensionListItem in targetListFileExtensions)
            {
                CodeTechnologyFileExtensionEntity fileExtension = new CodeTechnologyFileExtensionEntity();
                fileExtension.FileExtension = fileExtensionListItem.Value;

                codeTechnology.CodeTechnologyFileExtension.Add(fileExtension);
            }
            
            codeTechnology.Save(true);

which simply uses the TargetListItems property to extract each embedded list box item from the user control and adds to the right LLBLGen entity property and calls Save.

Any help appreciated

Attachments
Filename File size Added on Approval
FormViewCode.zip 4,925 26-Feb-2007 10:39.46 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Feb-2007 08:42:59   

Would you please post the code in the PerformSelect event?

Posts: 254
Joined: 16-Nov-2006
# Posted on: 26-Feb-2007 09:32:23   

Sure

protected void llbGenCodeTechnologiesDataSource_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs e)
    {
        CodeTechnologyCollection codeTechnologies = new CodeTechnologyCollection();
        codeTechnologies.GetMulti(null);

        llbGenCodeTechnologiesDataSource.EntityCollection = codeTechnologies;
    }
Posts: 254
Joined: 16-Nov-2006
# Posted on: 26-Feb-2007 10:00:35   

Btw why doesn't the forum support attachments, this would be a great way to submit code samples if required.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Feb-2007 10:26:32   

MattAdamson wrote:

Btw why doesn't the forum support attachments, this would be a great way to submit code samples if required.

It is enabled, click on the paperclip with the [+] in the header of your post. I think though why you didn't see that, the user role didn't have the right to add an attachment in a couple of forums, like this one simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 26-Feb-2007 10:40:51   

Thanks, attachment with code posted, look forward to a response.

Posts: 254
Joined: 16-Nov-2006
# Posted on: 26-Feb-2007 14:25:24   

Any ideas? Do you need any further information?

Aurelien avatar
Aurelien
Support Team
Posts: 162
Joined: 28-Jun-2006
# Posted on: 26-Feb-2007 16:14:50   

I've just saw your code, and you never set TargetListDataSource to a value... did I miss something ?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Feb-2007 16:18:10   

I also thought that would be the issue. I think you need this: (haven't tested this) <uc1:TransferTextToList ID="transferFileExtensionsToList" SourceTextBoxCaption="" runat="server" DataSource='<%# Bind("CodeTechnologyFileExtension ") #%>' />

Frans Bouma | Lead developer LLBLGen Pro
Posts: 254
Joined: 16-Nov-2006
# Posted on: 01-Mar-2007 09:49:05   

That's it thanks without the empty space at the end Bind call though.