2

I have two tables:

Products
-ProductID,
-ProductName,
-ProductCategoryID,

ProductCategories
-ProductCategoryID,
-ProductCategoryName,

I am using a dataset and I can successfully set up a relationship from the Products [ProductCategoryID] to the ProductCategoryID table. How do I get the Gridview to show up with ProductCategoryName rather than the integer reference?

I'm accustomed to Access where this just happens by default but it doesn't seem to work that way in Visual Studio.

1
  • You need to show your GridView markup, and how you're doing the databinding for the GridView for someone to really accurately help you. Commented May 29, 2012 at 19:25

4 Answers 4

1

Create a table join between your two tables in your query. For example, to display a single column:

SELECT ProductCategoryName FROM Products
JOIN ProductCategories ON
Products.ProductCategoryID = ProductCategories.ProductCategoryID

myGrid.DataSource = myDataSet;
myDataSet.Bind();
Sign up to request clarification or add additional context in comments.

Comments

0

Ok, you need to provide more information on how are you working with the gridview. Assuming that you are filling everything correctly and that you're working with columns over the .aspx, have you tried

<asp:GridView ID="yourId" runat="server" AutoGenerateColumns="false"> 
<Columns> 
...
    <asp:BoundField DataField="ProductCategories.ProductCategoryName" HeaderText="Category" /> 
...
</Columns> 

Comments

0

Depending on your implementation, it may be worth considering a viewmodel-based approach. Create a new class

ProductModel
-ProductId
-ProductCategoryName
-ProductName

Bind your grid to a collection of this object instead of your database object. This won't work well for every implementation but it is worth suggesting.

Comments

0

select a.ProductID,a.ProductName,b.ProductCategoryName from Products a,ProductCategories b where a.ProductCategoryID=b.ProductCategoryID

myGrid.DataSource = myDataSet; myDataSet.Bind();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.