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.



Thursday, December 1, 2011

Disable AutoComplete Feature in ASP.NET controls

a) There is an AutoCompleteType in TextBox Property and it will not disable in FireFox

b) in the TextBox set autocomplete="off"

Works both in IE and FireFox

c) the same above, but add as attribute in code behind
txtDate.Attributes.Add("autocomplete", "off");


Tuesday, October 11, 2011

Show Friendly Dates in Pages

Mostly when displaying null dates it appears in the screen as 1/1/0001. To avoid that we can create a readonly property for Example JOINDATESTRING where

public string JoinDateString
{
   get
  {
       if (StartDate == DateTime.MinValue)
      {
           return String.Empty();
      }
     else
    {
       return StartDate.ToString("dd/MM/yyyy");
    }
 }
}

Wednesday, September 14, 2011

Maintain Scroll Position After Postbacks


1- In Web.config, in  page section  declare <pages maintainScrollPositionOnPostBack="true" />, which maintains scroll position for all pages in the site.



2- To set for an individual page, in the page declaration  <%@ Page MaintainScrollPositionOnPostback="true" %> or in the codebehind  set  System.Web.UI.Page.MaintainScrollPositionOnPostBack = true  

Thursday, September 1, 2011

Formatting GridView

To Format the values displayed in GridView:
For BOUNDCOLUMN, use the DataFormatString argument

For TEMPLATECOLUMN, use the second argument of Bind() to format data
Eg:

See complete list of formatting:
Source :http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx


Format character
Description
Example
C or c
Displays numeric values in currency format. You can specify the number of decimal places.
Format: {0:C}
123.456 -> $123.46
Format: {0:C3}
123.456 -> $123.456
D or d
Displays integer values in decimal format. You can specify the number of digits. (Although the type is referred to as "decimal", the numbers are formatted as integers.)
Format: {0:D}
1234 -> 1234
Format: {0:D6}
1234 -> 001234
E or e
Displays numeric values in scientific (exponential) format. You can specify the number of decimal places.
Format: {0:E}
1052.0329112756 -> 1.052033E+003
Format: {0:E2}
-1052.0329112756 -> -1.05e+003
F or f
Displays numeric values in fixed format. You can specify the number of decimal places.
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567
G or g
Displays numeric values in general format (the most compact of either fixed-point or scientific notation). You can specify the number of significant digits.
Format: {0:G}
-123.456 -> -123.456
Format: {0:G2}
-123.456 -> -120
N or n
Displays numeric values in number format (including group separators and optional negative sign). You can specify the number of decimal places.
Format: {0:N}
1234.567 -> 1,234.57
Format: {0:N4}
1234.567 -> 1,234.5670
P or p
Displays numeric values in percent format. You can specify the number of decimal places.
Format: {0:P}
1 -> 100.00%
Format: {0:P1}
.5 -> 50.0%
R or r
Displays Single, Double, or BigInteger values in round-trip format.
Format: {0:R}
123456789.12345678 -> 123456789.12345678
X or x
Displays integer values in hexadecimal format. You can specify the number of digits.
Format: {0:X}
255 -> FF
Format: {0:x4}
255 -> 00ff

d
Short date pattern.
Format: {0:d}
6/15/2009 1:45:30 PM -> 6/15/2009
D
Long date pattern.
Format: {0:D}
6/15/2009 1:45:30 PM ->Monday, June 15, 2009
f
Full date/time pattern (short time).
Format: {0:f}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45 PM
F
Full date/time pattern (long time).
Format: {0:F}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 1:45:30 PM
g
General date/time pattern (short time).
Format: {0:g}
6/15/2009 1:45:30 PM -> 6/15/2009 1:45 PM
G
General date/time pattern (long time).
Format: {0:G}
6/15/2009 1:45:30 PM -> 6/15/2009 1:45:30 PM
M or m
Month/day pattern.
Format: {0:M}
6/15/2009 1:45:30 PM -> June 15
O or o
Round-trip date/time pattern.
Format: {0:o}
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30.0900000
R or r
RFC1123 pattern (for information, see DateTimeFormatInfo.RFC1123Pattern).
Format: {0:R}
6/15/2009 1:45:30 PM -> Mon, 15 Jun 2009 20:45:30 GMT
s
Sortable date/time pattern.
Format: {0:s}
6/15/2009 1:45:30 PM -> 2009-06-15T13:45:30
t
Short time pattern.
Format: {0:t}
6/15/2009 1:45:30 PM -> 1:45 PM
T
Long time pattern.
Format: {0:T}
6/15/2009 1:45:30 PM -> 1:45:30 PM
u
Universal sortable date/time pattern.
Format: {0:u}
6/15/2009 1:45:30 PM -> 2009-06-15 20:45:30Z
U
Universal full date/time pattern.
Format: {0:U}
6/15/2009 1:45:30 PM -> Monday, June 15, 2009 8:45:30 PM
Y or y
Year month pattern.
Format: {0:Y}
6/15/2009 1:45:30 PM -> June, 2009