Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Issue with LinqData Source and GridView

Avatar of justin_smith
justin_smithFlag for Australia asked on
.NET ProgrammingC#ASP.NET
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
Avatar of sunithnair
sunithnair

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

Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers