Monday, June 4, 2012

Showing Values in Nested a Grid

Many times I had came across a situation to  display Master-Detail in a grid. Normally we accomplish this by binding the Detailgrid  with on Item Data Bound of the Master Grid.

But if we have all Master Detail Data returning in a Collection,
for ex.
Order 1 , Customer1, OrderDate
   Item1 , Item Name, Item Price, Qty, Total Price
   Item2 , Item Name, Item Price, Qty, Total Price
   Item3 , Item Name, Item Price, Qty, Total Price
   Item4 , Item Name, Item Price, Qty, Total Price

Order 2 , Customer2, OrderDate
   Item1 , Item Name, Item Price, Qty, Total Price
   Item2 , Item Name, Item Price, Qty, Total Price
   Item3 , Item Name, Item Price, Qty, Total Price
   Item4 , Item Name, Item Price, Qty, Total Price

Order3 , Customer3, OrderDate
   Item1 , Item Name, Item Price, Qty, Total Price
   Item2 , Item Name, Item Price, Qty, Total Price
   Item3 , Item Name, Item Price, Qty, Total Price
   Item4 , Item Name, Item Price, Qty, Total Price

we can link
1) Create a User Control with a Property for Example Orders
Eg:
public object Orders
{
   set
   {
      if (value is Order )
      {
         rptDetail.DataSource = ((Order)value).OrderItems;
         rptDetail.DataBind();
      }
   }
}

And in the ASPX page when calling the grid, pass the Parameter Orders with 'Container.DataItem'

Eg:
EP:UCOrderItems ID="ucOrderItems" runat="server" Orders=''/>

This will bind the collection to the child grid


Sending Multiple Parameters using COMMANDARGUMENTS

To send multiple parameters from CommandArguments in a grid (for ex. Button is
 '<%# String.Format("{0},{1}", Eval("FileID"), Eval("JobID")) %>'


<asp:Button ID="btnUnlinkFile" runat="server" CssClass="button gray small" CommandName="unlinkfile" CommandArgument='<%# String.Format("{0},{1}", Eval("FileID"), Eval("JobID")) %>' ToolTip="Unlink this File" Text="x" OnClientClick="return confirm('Are you certain you want to Unlink this file ?');" />

Wednesday, March 14, 2012

Compile Error: 'xxxxException' is a 'namespace' but is used like a 'type'

Reason: CLASS name is same as its NAMESPACE name.
I had the foldername same as the class name and raised the error. To resolve this compilation error Renamed the folder.