troubleshooting Question

Issue with LinqData Source and GridView

Avatar of justin_smith
justin_smithFlag for Australia asked on
.NET ProgrammingASP.NETC#
7 Comments1 Solution410 ViewsLast Modified:
Hi,

I have a scenario similar to the following
There is Product Table with its details
And there is another Supplier Table with supplier details

Product Table has productID as the primary key and SupplierID
The SupplierID is the PK fir Supplier table

But in the DB side SupplierID is not tagged as the FK on the Product table
But we know how it works.. ANd i am not permitted to change anything on the DB

Ok so in the ASP.Net project i drag both these table in to the ORM file .dbml

And add associtation between the Supplier(Parent)  and Product (Child)


And i want to diaply the info in a GridView
In the Gridview instead of Supplier ID i want to have SupplierName (which is a prop in Supplier Table) along with the product tables..


So this is what i do


    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataKeyNames="ProductID" DataSourceID="LDS_Product">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

                <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True"
                    SortExpression="ProductID" />

                <asp:BoundField DataField="ProductName" HeaderText="ProductName" InsertVisible="False" ReadOnly="True" SortExpression="ProductName" />

                <asp:TemplateField HeaderText="Supplier " SortExpression="Supplier.SupplierID">
                    <ItemTemplate>
                        <%#Eval("Supplier.SupplierName")%>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:LinqDataSource ID="LDS_Product" runat="server" ContextTypeName="DataClassesDataContext"
            EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Products"
            Where="ProductName == @PName">
            <WhereParameters>
                <asp:ControlParameter ControlID="TB_Product" Name="ProductName " PropertyName="Text" Type="String" />
            </WhereParameters>
        </asp:LinqDataSource>


I am sure there is something missing .. cos how can i mention Supplier.SupplierName where supplier is not a property on Product Data class..


And i get this error
Server Error in '/CustomerService' Application.
DataBinding: 'Product' does not contain a property with the name 'Supplier.


What is going wrong here


Can i add property Supplier declaratively without changing code..? or do a join in the LinqdataSource what is used by the GridView...


I am pretty new to these areas..

Any detailed help is appreciated

Thanks

ASKER CERTIFIED SOLUTION
sunithnair

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros