Simple Question: Databinding w/ Datasource

Posts   
 
    
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 09-Jul-2007 18:45:10   

I have a web form that retrieves an Entity from a webserive (all that works great) but I want to bind the data to a bunch of Textboxes on the form. The only way I could figure out how to do this was:

   EntityCollection col = new EntityCollection();
   col.Add(employee);
   fvEmployee.DataSource = col;
   fvEmployee.DataBind();

This works fine, but doesn't let me do any design-time setting of the binding properties for the fields on the web form. If I use the "LLBLGenProDataSource2" control and set the Factory to my Entity, it allows me set the binding paramaters at design time since it knows what the object looks like.

However, I can't figure out how to pass my "employee" entity to the "LLBLGenProDataSource2" control and then bind the controls... I tried:

   dsEmployee.EntityCollection.Add(employee);
   dsEmployee.DataBind();

But that doesn't work, all I get is a blank form with none of the data rendered. I'm sure this is something basic, but I don't see any samples that explain how this might be accomplished...

Thanks in advance!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 03:00:13   

Hi dtkujawski. You need to:

1. set yourLLBLGenDataSource2.LivePersistence = false

**2. **Create an EventHandler for PerformSelect of you LLBLGenDataSource2. (you can double click at the event in propertie's window.

3. Clear your collection and add your entity, this code must be placed of perfomSelect eventHandler:

protected void LLBLGenProDataSource2_1_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
{
    e.ContainedCollection.Clear();
    e.ContainedCollection.Add(myEmployeeFromWS);
}

For more info please read the Databinding section of LLBLGenPro Help Let us know if there's anything else you want assistance. simple_smile

David Elizondo | LLBLGen Support Team
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 10-Jul-2007 03:56:32   

Awesome - that works great for the select, but for some reason the PerformWork is not firing. Basically I have a FormView on the web page with a bunch of fields and a button with an onClick event that fires the following code:

protected void Update_Click(object sender, EventArgs e)
{
   fvEmployee.UpdateItem(true);         
}

Then, I have a very simple PerformWork event defined:

protected void dsEmployee_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
{
   EmployeeService.Employee ws = new EmployeeService.Employee();
   ws.Update(e.Uow);
}

But, the code never executes the PerformWork event no matter what I try...

note> I am using the trial version, code that matter?

Thanks again, in advance!!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 04:09:05   

Please answer this:

  1. Are you sure the DS ****PerformWork ****property is pointing to your PerformWork eventHandler? something like:
<llblgenpro:LLBLGenProDataSource2 ID="_SomeEntityDS" runat="server" MaxNumberOfItemsToReturn="1" DataContainerType="EntityCollection" AdapterTypeName="SAA.DatabaseSpecific.DataAccessAdapter, SAADBSpecific" EntityFactoryTypeName="SAA.FactoryClasses.SomeEntityEntityFactory, SAA" LivePersistence="False" OnPerformSelect="_SomeEntityDS_PerformSelect" [b]OnPerformWork="_SomeEntityDS_PerformWork[/b]"/>
  1. What is the fvEmployee.CurrentMode before you call Update?

  2. What is the yourEntityFromWS.IsNew value before you call Update?

David Elizondo | LLBLGen Support Team
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 10-Jul-2007 04:18:56   

Thanks for the quick reply... It's driving me crazy!

1) Yes - I inspected it to make sure, but also when I double click in Visual Studio it takes me to the correct event handler

2) Edit

3) entity.IsNew = false note: I tried overridding it to "true" in the watch window, just to see if anything would change and nothing.

Here is what my DataSource2 looks like:

<llblgenpro:LLBLGenProDataSource2 ID="dsEmployee" runat="server" DataContainerType="EntityCollection" EntityFactoryTypeName="QuestPOC.FactoryClasses.EmployeeEntityFactory, QuestPOC" LivePersistence="False" OnPerformSelect="dsEmployee_PerformSelect" OnPerformWork="dsEmployee_PerformWork"></llblgenpro:LLBLGenProDataSource2>

Any other thoughts?

dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 10-Jul-2007 04:35:15   

Anything thing that I thought was odd was that DataSource2.UnitOfWorkObject is null both before and after the call to "UpdateItem"... I would have expected this object to be createdand to store the changes at the very least?

note: I tried this on another form linking a GridView to a DataSource2 and using the default Edit/Update capabilities - still didn't work (although PerformSelect is fine). Then I made my own UpdateRow command on the xxxxxx_RowCommand event handler and the PerformWork still did not fire...

grdEmployee.UpdateRow(Convert.ToInt32(e.CommandArgument), false);

still stumped over here... when should the UnitOfWorkObject be populated?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 06:28:24   

At this point I'm out of clues disappointed Could you show me your ASPX and CS behind file? You can do this opening a HelpDesk thread and attach files so only you and Support Team can see the conversation. You can also email me the zip-project (if you can and you want) to david.elizondo(AT)llblgen.com.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39616
Joined: 17-Aug-2003
# Posted on: 10-Jul-2007 10:44:54   

Do you do anything like this: - create FormView control with textboxes - bind datasource control to formview - bind textboxes to fields in object of formview (with Eval(..) or BInd...) - add entity to collection in datasourcecontrol

?

Frans Bouma | Lead developer LLBLGen Pro
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 10-Jul-2007 15:58:45   

Yes - those are my exact steps... I only have 8 lines of code in the CS file:

protected void Update_Click(object sender, EventArgs e)
        {
            fvEmployee.UpdateItem(false);
            //Cancel_Click(sender, e);
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("default.aspx", true);
        }

        protected void dsEmployee_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
        {
            EmployeeService.Employee ws = new EmployeeService.Employee();
            EmployeeEntity employee = ws.Read(Convert.ToInt32(Request["empID"]));

            e.ContainedCollection.Clear();
            e.ContainedCollection.Add(employee);
        }

        protected void dsEmployee_PerformWork(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformWorkEventArgs2 e)
        {
            //update data to web service
            EmployeeService.Employee ws = new EmployeeService.Employee();
            ws.Update(e.Uow);
        }

And, the only thing in my ASPX file is the FormView and the datasource - that's it!!

    <form id="form1" runat="server">
    <div>
        <span style="font-size: 16pt">
        Employee Details:</span><br />
        <asp:FormView ID="fvEmployee" runat="server" DataSourceID="dsEmployee" DefaultMode="Edit" DataKeyNames="Empid" >
            <EditItemTemplate>
        <table>
            <tr>
                <td>ID:</td>
                <td><asp:TextBox ID="txtID" runat="server" ReadOnly="True" Text='<%# Bind("empID") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Name:</td>
                <td><asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Department:</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Deptid") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Title:</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Title") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2"><hr /></td>
            </tr>
            <tr>
                <td>Gender:</td>
                <td>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Sex") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Date of Birth:</td>
                <td>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Dob") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Age:</td>
                <td>
                    <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Age") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Address Line1:</td>
                <td>
                    <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Address1") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Address Line2:</td>
                <td>
                    <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("Address2") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>City:</td>
                <td>
                    <asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("City") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>State:</td>
                <td>
                    <asp:TextBox ID="TextBox9" runat="server" Text='<%# Bind("State") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Zip:</td>
                <td>
                    <asp:TextBox ID="TextBox10" runat="server" Text='<%# Bind("Zip") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2"><hr /></td>
            </tr>
            <tr>
                <td>Create User:</td>
                <td>
                    <asp:TextBox ID="TextBox11" runat="server" ReadOnly="True" Text='<%# Bind("CreateUserid") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Create Timestamp:</td>
                <td>
                    <asp:TextBox ID="TextBox12" runat="server" ReadOnly="True" Text='<%# Bind("CreateTimestamp") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Update User:</td>
                <td>
                    <asp:TextBox ID="TextBox13" runat="server" ReadOnly="True" Text='<%# Bind("UpdateUserid") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Update Timestamp:</td>
                <td>
                    <asp:TextBox ID="TextBox14" runat="server" ReadOnly="True" Text='<%# Bind("UpdateTimestamp") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td>Update Number:</td>
                <td>
                    <asp:TextBox ID="TextBox15" runat="server" ReadOnly="True" Text='<%# Bind("UpdateNo") %>'></asp:TextBox></td>
            </tr>
            <tr>
                <td colspan="2"><hr /></td>
            </tr>
            <tr>
                <td><asp:Button ID="Cancel" runat="server" Text="Cancel" OnClick="Cancel_Click" /></td>
                <td align="right"><asp:Button ID="Update" runat="server" Text="Update" OnClick="Update_Click" /></td>
            </tr>
        </table>
            </EditItemTemplate>
        </asp:FormView>
    </div>
        <llblgenpro:LLBLGenProDataSource2 ID="dsEmployee" runat="server" DataContainerType="EntityCollection"
            EntityFactoryTypeName="QuestPOC.FactoryClasses.EmployeeEntityFactory, QuestPOC"
            LivePersistence="False" OnPerformSelect="dsEmployee_PerformSelect" OnPerformWork="dsEmployee_PerformWork">
        </llblgenpro:LLBLGenProDataSource2>
    </form>
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Jul-2007 21:42:39   

I figured out that DataKeyNames is case insensitive, if I change EmployeeId to EmployeeID the retrieve does work but the Update doesn't. However you have a valid DataKeyNames (I see you EmployeeEntity and everything is OK). However here:

  <td><asp:TextBox ID="txtID" runat="server" ReadOnly="True" Text='<%# Bind("empID")

your aren't using the correct field name. This shouldn't matter, but just to be sure, rewrite your Bind(fieldname) and try again.

David Elizondo | LLBLGen Support Team
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 10-Jul-2007 21:52:28   

I'm willing to try anything at this point!! I went ahead and changed the Binding field name, but it didn't have any effect (ie. it didn't call PerformWork and the field was still populating correctly on the screen).

Did you get the .ZIP with the full source code last night via. e-mail? Maybe that would provide additional insight to you?

It's got to be something stupid simple, right? I just cant' figure out why I'm having this problem and others are not... lucky me, I guess!!

dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Jul-2007 06:01:58   

David - any new ideas on this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Jul-2007 10:32:31   

Hi dtkujawski. I finally found the problem simple_smile : the **AdapterTypeName **attribute of the _LLBLGenProDataSource2 _is missing. The _LLBLGenDataSource _needs this info so the _PerformWork _call makes sense.

So you should change this

<llblgenpro:LLBLGenProDataSource2 ID="dsEmployee" runat="server" DataContainerType="EntityCollection" 
    EntityFactoryTypeName="QuestPOC.FactoryClasses.EmployeeEntityFactory, QuestPOC"
    LivePersistence="False" OnPerformSelect="dsEmployee_PerformSelect" OnPerformWork="dsEmployee_PerformWork">
</llblgenpro:LLBLGenProDataSource2>

to this

<llblgenpro:LLBLGenProDataSource2 ID="dsEmployee" runat="server" DataContainerType="EntityCollection" AdapterTypeName="QuestPOC.DatabaseSpecific.DataAccessAdapter, QuestPOCDBSpecific"
    EntityFactoryTypeName="QuestPOC.FactoryClasses.EmployeeEntityFactory, QuestPOC"
    LivePersistence="False" OnPerformSelect="dsEmployee_PerformSelect" OnPerformWork="dsEmployee_PerformWork">
</llblgenpro:LLBLGenProDataSource2>

Tell me if everything is OK with that simple_smile

David Elizondo | LLBLGen Support Team
dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Jul-2007 16:16:39   

Great, thanks... that worked, but it brings up a question on my end...

It doesn't seem like that should be necessary in order to call the PerformWork since I am overriding the calls to the database by using WebServices. That solution requires me to reference the DBSpecific project, which I don't mind doing, but I was was thinking I didn't need to do since the presentation layer doesn't interact with the database directly.

Am I missing something conceptual here?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Jul-2007 16:48:31   

LLBLGenProdataSource, as it's name implies is meant to use the DAL to deal with the data (Fetch/Save/Delete).

The issue is that you wanted to use it to have design time flexability, and it was meant to be used directly on the data.

Still your point of view makes sence to me, so I'll escilate it.

dtkujawski avatar
dtkujawski
User
Posts: 39
Joined: 05-Jul-2007
# Posted on: 11-Jul-2007 16:51:20   

Thanks... I'll go ahead and mark this thread as complete, just to keep things clean in the forum...

I appreciate everyone's help with this - I was pulling my hair out! simple_smile