I am trying to accomplish a Master Detail Display here.
The master item is ProductName and Child items are the details of the Product.
Example:
Dell Desktop V305
- Model: Black - 23877487y24y
- Mother Board - Intel ....
- RAM - 3 GB DDR
HP Printer
- Ink Jet C 7770
- 4 Catridge
- Return Policy: blah blah
The ProductName (Master) comes from one table and children come from another. They are linked by Inventory_Item_Id.
I am cleaning up someones code. so I am restricted to datareader and nested repeater.
Please help me with how to go about it.
thanks for the help in advance.
Here is the code I have done. I am able to show the product name but child elements is where I am having trouble.
[B].aspx [/B]
<asp:repeater id="rptProd" Runat="server" OnItemDataBound="rptProducts_ItemDataBound">
<ItemTemplate>
<tr>
<td width=50% style="padding: 1px; padding-left: 12px;">
<%# DataBinder.Eval(Container.DataItem, "Product_Name")%>
<table class=invoiceSubItems width=100% style="margin-top: 8px; margin-bottom: 8px; <asp:literal id="litStyle" runat="server" />" cellpadding=0 cellspacing=0>
<asp:Repeater id="rptDetails" runat="server">
<ItemTemplate>
<tr>
<td class="invoiceSubLineItem" nowrap valign=top style="padding-left: 8px;"><%# DataBinder.Eval( Container.DataItem ,"ELEMENTTYPE" )%>:</td>
<td width=20px> </td>
<td class="invoiceSubLineItem" valign=top><%# DataBinder.Eval( Container.DataItem ,"ELEMENT" )%></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</td>
<td align="center" width=25% valign=top style="padding: 1px;"><%# DataBinder.Eval(Container.DataItem, "Quantity")%></td>
<td align="right" width=25% valign=top style="padding: 1px; padding-right: 12px;"><%# DataBinder.Eval(Container.DataItem, "Price", "{0:c}")%></td>
</tr>
</ItemTemplate>
</asp:repeater>
[B]Code Behind:[/B]
public void rptProducts_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
int IndexNow = e.Item.ItemIndex - 1;
if (IndexNow >= 0 && rptProd.Items.Count > IndexNow)
{
Repeater nestedRepeater = (Repeater)rptProd.Items[IndexNow].FindControl("rptDetails");
//This returns the Inventory Item Id that links the Master and Child Records\
//The Child records need to be fetched uding the Inventory Item Id t
OracleDataReader YourDr = getInventoryItemId();
string[] tmpStr= new string[5];
if (nestedRepeater != null)
{
for(int i=0; i < getCountofInventoryItemId(); i++)
{
tmpStr[i]=YourDr[i].ToString();
OracleDataReader dr = BundleSpec(tmpStr[i]);
nestedRepeater.DataSource = YourDr;
nestedRepeater.DataBind();
}
}
}
///Method calls used inside the ItemBound Event
public int getCountofInventoryItemId()
{
int countOfItems;
OracleConnection con = new OracleConnection();
OrderEntry.Components.DAL.Database.CheckState(con);
string strInventoryItemId = "SELECT COUNT(INVENTORY_ITEM_ID) FROM ORDER_DETAIL WHERE ORDER_ID ='{0}'";
string ID = Convert.ToString(Request["ID"].Trim());
strInventoryItemId = string.Format(strInventoryItemId, ID);
string countRdr = OrderEntry.Components.DAL.Database.GetOracleScalar(strInventoryItemId);
countOfItems = Convert.ToInt16(countRdr);
return countOfItems;
}
public OracleDataReader getInventoryItemId()
{
OracleConnection con = new OracleConnection();
OrderEntry.Components.DAL.Database.CheckState(con);
string strInventoryItemId = "SELECT DISTINCT INVENTORY_ITEM_ID FROM ORDER_DETAIL WHERE ORDER_ID ='{0}'";
string ID = Convert.ToString(Request["ID"].Trim());
strInventoryItemId = string.Format(strInventoryItemId, ID);
return OrderEntry.Components.DAL.Database.GetOracleDataReader(strInventoryItemId);
}
public OracleDataReader ProductName()
{
OracleConnection con = new OracleConnection();
OrderEntry.Components.DAL.Database.CheckState(con);
string strProductName= "SELECT PRODUCT_NAME,QUANTITY,PRICE,INVENTORY_ITEM_ID FROM ORDER_DETAIL WHERE ORDER_ID ='{0}'";
string ID = Convert.ToString(Request["ID"].Trim());
strProductName = string.Format(strProductName, ID);
return OrderEntry.Components.DAL.Database.GetOracleDataReader(strProductName, con);
}
public OracleDataReader BundleSpec(string INV_ID)
{
string ID = Convert.ToString(INV_ID);
OracleConnection con = new OracleConnection();
OrderEntry.Components.DAL.Database.CheckState(con);
string inv_sql = "SELECT ELEMENTTYPE, ELEMENT FROM PPC_TREE_BUNDLE_ELEMENTS WHERE INVENTORY_ITEM_ID = '{0}' ORDER BY SORT_ORDER";
inv_sql = string.Format(inv_sql, ID);
return OrderEntry.Components.DAL.Database.GetOracleDataReader(inv_sql, con);
}
Thanks for all your help!