Declarative databinding problems - asp.net

Posts   
 
    
Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 07-Apr-2007 11:10:04   

LLBLGen Pro version 2.0.0.0, Trial version, SelfService Single class .Net 2.0 SqlServer 2000, VSNet 2005

I'm trying to set up a paged detailsview control which gets its data from a LLBLGenDataSource control retrieving all records from a table.

Below this on the web page is a GridView control which has its own associated LLBLGenDataSource control.

I have tried to set up the GridView's datasource control with a controlparameter pointing to the DataKey property of the DetailsView, so that it displays foreign key records from a field in the DetailsView, but I can't get this to work. The GridView just displays all records.

I have implemented code-behind in the DetailsView databound event which sets the GridView's datasource.refetch property to 'true' and rebinds the grid - this happens when you move to the next page with the detailsView.

Even more annoyingly, and probably an MS bug, is that often, the datasource control loses its EntityCollectionTypeName value and will not retain it - even if I switch to source view and type it in manually.

Have I missed something?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 07-Apr-2007 11:58:03   

Here's an example, master-detail, paging code:

page:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="SD.LLBLGen.Pro.ORMSupportClasses" Namespace="SD.LLBLGen.Pro.ORMSupportClasses" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        Master detail with 2 grids, 2 datasources and 1 combobox filter for the master set.<br />
        <br />
        Select country:&nbsp;
        <asp:DropDownList ID="_countrySelector" runat="server" AutoPostBack="true">
            <asp:ListItem>Germany</asp:ListItem>
            <asp:ListItem>Brazil</asp:ListItem>
            <asp:ListItem>Canada</asp:ListItem>
            <asp:ListItem>UK</asp:ListItem>
        </asp:DropDownList><br />
        <br />
        Customers:<br />
        <asp:GridView ID="_customersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerId" 
            DataSourceID="_customersDS" AllowPaging="True" PageSize="5">
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" ReadOnly="True" SortExpression="CustomerId" />
                <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />
                <asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />
                <asp:BoundField DataField="ContactTitle" HeaderText="ContactTitle" SortExpression="ContactTitle" />
                <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="Region" HeaderText="Region" SortExpression="Region" />
                <asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
                <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
                <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Fax" SortExpression="Fax" />
            </Columns>
        </asp:GridView>
        <cc1:LLBLGenProDataSource2 ID="_customersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" 
            DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.CustomersEntityFactory, NWTest" EnablePaging="True">
            <SelectParameters>
                <asp:ControlParameter ControlID="_countrySelector" Name="Country" PropertyName="SelectedValue" />
            </SelectParameters>
        </cc1:LLBLGenProDataSource2>
        <br />
        Orders:<br />
        <asp:GridView ID="_ordersGrid" runat="server" AutoGenerateColumns="False" DataKeyNames="OrderId" DataSourceID="_ordersDS">
            <Columns>
                <asp:BoundField DataField="OrderId" HeaderText="OrderId" ReadOnly="True" SortExpression="OrderId" />
                <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" SortExpression="CustomerId" />
                <asp:BoundField DataField="ShipName" HeaderText="ShipName" SortExpression="ShipName" />
                <asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress" SortExpression="ShipAddress" />
                <asp:BoundField DataField="ShipCity" HeaderText="ShipCity" SortExpression="ShipCity" />
                <asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion" SortExpression="ShipRegion" />
                <asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode" SortExpression="ShipPostalCode" />
                <asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" SortExpression="ShipCountry" />
            </Columns>
        </asp:GridView>
        <cc1:LLBLGenProDataSource2 ID="_ordersDS" runat="server" AdapterTypeName="NWTest.DatabaseSpecific.DataAccessAdapter, NWTestDBSpecific" 
            DataContainerType="EntityCollection" EntityFactoryTypeName="NWTest.FactoryClasses.OrdersEntityFactory, NWTest" 
                OnPerformSelect="_ordersDS_PerformSelect">
            <SelectParameters>
                <asp:ControlParameter ControlID="_customersGrid" Name="CustomerId" PropertyName="SelectedValue" />
            </SelectParameters>
        </cc1:LLBLGenProDataSource2>

    </form>
</body>
</html>

The page uses adapter but for selfservicing it is the same.

code behind is empty.

Be sure to set paging ON on the datasource.

About the datasource attributes getting lost: yeah that's an annoying vs.net issue. Be sure to have SP1 for vs.net 2005 installed, as that helps a lot simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Meteor
User
Posts: 67
Joined: 06-Apr-2007
# Posted on: 08-Apr-2007 01:16:52   

Thanks for that, however the only difference between my scenario and your example, is that I'm trying to bind the second grid to a value other than the primary key. Almost as if the 'Address' field in the Customers table was a foreign key to an 'Address' table, and my second grid is listing the address records from that table. I tried something like <SelectParameters> <asp:ControlParameter ControlID="_artistsGrid" Name="CollectionId" PropertyName="DataKey('CollectionId')" /> </SelectParameters>

(after having set 'CollectionId' as a DataKey in the upper gridview) but that didn't work at all rage

I'll check the sp level of vs2005.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Apr-2007 12:29:36   

I think that's a limitation of the gridview in asp.net, as its 'selectedvalue' is the PK of the selected row.

What you could do is set the filter of the child datasource manually in the code behind. Just set the datasource's property 'FilterToUse' to a predicateexpression build with the selected row in the parent grid. If you need help with that, let me know. I'll see if I have one if these setup in my testforms. (edit) I don't have this particular setup in my testforms. I can create one for you, if you want to.

Frans Bouma | Lead developer LLBLGen Pro