Return to Snippet

Revision: 34265
at October 20, 2010 01:55 by housecor


Updated Code
//gets product and joins to ProductType to get associated type, then from there to product category to get the category associated with the type. 
Entities db = new Entities();
rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
rptProducts.DataBind();

//The webform:
//Note the use of .eval instead of GetPropertyValue when calling properties that contain nested objects.
<tr class="product_row" rel="<%#DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
   <td><asp:CheckBox runat="server" ID="chkProduct" /></td>
   <td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
   <td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
   <td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
</tr>

Revision: 34264
at October 20, 2010 01:55 by housecor


Updated Code
//gets product and joins to ProductType to get associated type, then from there to product category to get the category associated with the type. 
Entities db = new Entities();
rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
rptProducts.DataBind();

//The webform:
<tr class="product_row" rel="<%#DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
   <td><asp:CheckBox runat="server" ID="chkProduct" /></td>
   <td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
   <td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
   <td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
</tr>

Revision: 34263
at October 20, 2010 01:54 by housecor


Updated Code
//gets product and joins to ProductType to get associated type, then from there to product category to get the category associated with the type. 
Entities db = new Entities();
rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
rptProducts.DataBind();

//The webform:
					<tr class="product_row" rel="<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
						<td><asp:CheckBox runat="server" ID="chkProduct" /></td>
						<td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
						<td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
						<td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
					</tr>

Revision: 34262
at October 20, 2010 01:53 by housecor


Updated Code
//gets product and joins to ProductType to get associated type, then from there to product category to get the category associated with the type. 
Entities db = new Entities();
rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
			rptProducts.DataBind();

//The webform:

					<tr class="product_row" rel="<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
						<td><asp:CheckBox runat="server" ID="chkProduct" /></td>
						<td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
						<td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
						<td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
					</tr>

Revision: 34261
at October 20, 2010 01:52 by housecor


Initial Code
Entities db = new Entities();
rptProducts.DataSource = db.Products.Include("ProductType.ProductCategory");
			rptProducts.DataBind();

//The webform:

					<tr class="product_row" rel="<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>">
						<td><asp:CheckBox runat="server" ID="chkProduct" /></td>
						<td><%# DataBinder.Eval(Container.DataItem, "ProductType.ProductCategory.Name") %></td>
						<td><a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>"><%# DataBinder.Eval(Container.DataItem, "ProductType.Name") %></a></td>
						<td><%# DataBinder.GetPropertyValue(Container.DataItem, "DateCreated") %></td>
						<td>
                            <a href="Edit?id=<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>" title="Edit"><img src="/App_Themes/Admin/Images/icons/pencil.png" alt="Edit" /></a>
                            <a href="#" title="Delete" rel="<%# DataBinder.GetPropertyValue(Container.DataItem, "ProductID") %>" class="delete_product"><img src="/App_Themes/Admin/Images/icons/cross.png" alt="Delete" /></a> 
						</td>
					</tr>

Initial URL


Initial Description


Initial Title
Entity Framework include style join

Initial Tags


Initial Language
C#