开发者

Binding LinqDataSource to two separate Table

开发者 https://www.devze.com 2023-02-19 08:53 出处:网络
I have two tables: Entity ID (PK, int) Name Users Entity_ID (FK to the Entity.ID) FName LName Now I want to show all columns from both tables to my GridView using QueryString. I got the QueryStri

I have two tables:

Entity

ID (PK, int)

Name

Users

Entity_ID (FK to the Entity.ID)

FName

LName

Now I want to show all columns from both tables to my GridView using QueryString. I got the QueryString part through configuration of LDS. I cannot see how you can link both tables in one LDS?

Here is the markup of my code:

 <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
             AllowSorting="True" AutoGenerateColumns="False" 
             DataSourceID="LinqDataSource1" Height="209px" Width="648px">
             <Columns>
                 <asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="True" 
                     SortExpression="Name" />
                 <asp:BoundField DataField="Description" HeaderText="Description" 
                     ReadOnly="True" SortExpression="Description" />
                 <asp:BoundField DataField="Company" HeaderText="Company" ReadOnly="True" 
                     SortExpression="Company" />
                 <asp:BoundField DataField="Phone" HeaderText="Phone" ReadOnly="True" 
                     SortExpression="Phone" />
                 <asp:BoundField DataField="Fax" HeaderText="Fax" ReadOnly="True" 
                     SortExpression="Fax" />
                 <asp:BoundField DataField="Email" HeaderText="Email" ReadOnly="True" 
                     SortExpression="Email" />
                 <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" 
                     SortExpression="ID" />

                     <asp:BoundField DataField 开发者_JS百科= 'Bind("Users.FirstName")' />
             </Columns>
         </asp:GridView>
         <asp:LinqDataSource ID="LinqDataSource1" runat="server" 
             ContextTypeName="EntityRegistration.DataAccess.OISLinq2SqlVs1DataContext" 
             EnableInsert="True" EnableUpdate="True" EntityTypeName="" OrderBy="ID" 
             Select="new (Name, Description, Company, Phone, Fax, Email, ID)" 
             TableName="Entities" Where="ID == @ID">
             <WhereParameters>
                 <asp:QueryStringParameter Name="ID" QueryStringField="EntityID" Type="Int32" />
             </WhereParameters>
         </asp:LinqDataSource>

As you can see I have also added this column:

asp:BoundField DataField = 'Bind("Users.FirstName")'

Dont know what I am doing wrong here? Any comments?


You can definitely do that, if such connection exists in the LinqDataSource.

Your syntax looks strange though:

Try this one (don't now if this works):

 <asp:BoundField DataField = 'Users.FirstName' />

Or that one (this one does work):

<asp:TemplateField>
 <ItemTemplate>
  <asp:Literal ID="litFoo" runat="server" Text='<%# Bind("Users.FirstName") %>' />
 </ItemTemplate>
</asp:TemplateField>


You are binding to Firstname but your users has FName or is that a typo?

0

精彩评论

暂无评论...
验证码 换一张
取 消