05 May 2012

Using MID() to Cut Out a SubString

I have a filed that begins with numeirc characters and it ends with alpha character (like 0125461E). I want to alpha (E) part form the string and leave the remaining (0125461) field value.

we need to "cut" it out of our  IDNumber field.
Our example field is called {USERS. IDNumber}.
Now the way we cut strings out of other strings is with the MID() function. The MID function takes three parameters. The string on which to operate, where to start and the length of the string to return.

MID(String, Starting Character Position, Length of String to Return)

Supposing that {USERS. IDNumber } is going to return Justin Hill, we can see the result of various MID statements:
MID({USERS. IDNumber }, 8, 1) then we will get "E"
Also note that you may omit the final parameter (length) to return "the rest" of the string, like this:
MID({USERS. IDNumber  }, 8) 

Example:

//Declaring variable to display message...
Stringvar message;
if (MID({REP. IDNumber},  8 ,1)="E")
then message:="Employee" 

Pass value from main report to sub report

I am designing a report which includes sub report every thing is fine but i have to display the main report field value in sub report . To get the main report vale in to the sub report follow the bellow steps.
Step 1:
1. In main report create a formula, name it, edit it with the formula editor as follows:
Shared numbervar NAME := {Rep.Sno} 
Save formula.  Note that you should replace the name and type of variable and a formula with ones of your own
2. Now create a formula in your subreport, name it, edit it with the formula editor as follows:

Shared numbervar NAME;
NAME
3. Use formula created in step 2 in your report (drag drop in the report from formula fields.
Note that subreport is processed after the main report, so it's easier to pass values from main report to subreport.

01 May 2012

Display a serial number in RDLC report

I have developed a report in reportviewer using ASP.NET. I want to display serial number in report follow the below steps. In RDLC design drag and drop a text box from the toolbox and right click on it and select Expression as shown below.


An expression containing the RowNumber function, when used in a text box within a data region, displays the row number for each instance of the text box in which the expression appears. This function can be useful to number rows in a table.
Using RowNumber(Scope) function to display the row numbers. If scope is nothing then RowNumber(Nothing) provides the running count of rows in the outermost data region.

How to Change Date Format in .RDLC reports (MM/dd/yyyy)

In my Report Design i want to show date in the format of (MM/dd/yyyy). The column has the value in dd/MM/yyyy.  The output on the webform looks like this: 05/18/2012 to do this follow the below steps.
Step1: In RDLC design right click on the column/textbox and then it will open context menu as shown below then select the Expression option from the menu.
Step 2:When click on Expression then it will open a windows as shown below. Change the Expression statement as shown and then click on OK button.


RDLC report Text box/Column value formating

In my RDLC reports i want show 2 decimal points. Decimal value like 25.5000 now i want to show it in 2 decimal point in report (25.50). To do as shown below.
Use the "Round" function on your column or Textbox.
Some thing like  =Round(FieldName,2) 
where FieldName is the name of your column or the value you want to round off and 2 is the decimal places

Time Out downloading large files

When your downloading a table data in the format of excel sheet, while doing that it throws time out error due to lack of enough size. To download the file add the following tag in the web.config file as shown below.
Problem:

By default, Machine.config is configured to accept HTTP Requests upto 4096 KB (4 MB) and it is reflected in all your ASP.NET applications. You can change the Machine.config file directly, or you can change only the Web.config file of the application(s) you want to.
Open your Web.config file, and just below the <system.web> tag, add the following tag:

  <system.web>
    <httpRuntime executionTimeout="90"
            maxRequestLength="4096"
            useFullyQualifiedRedirectUrl="false"
            minFreeThreads="8"
            minLocalRequestFreeThreads="4"
            appRequestQueueLimit="100"
            enableVersionHeader="true"
    />
Now, just take a look at the maxRequestLength="4096"  and   executionTimeout="1000" attribute of the  <httpRuntime>  tag. As you may have realized, all you need to do is change the value to some other value of your choice (8192 for 8 Mb, 16384 for 16 Mb, 65536 for 64 Mb, and so on...).

17 April 2012

MS Chart Legend Properties and Hide Series Based on Condition

I have a MSChart that displays two series. The data is taken from a database. Sometimes I only want to display one of the series in my chart based on the condition. Follow the bellow steps to hide series.
                 Chart1.Series["Series Name"].Enabled = false; 


We can set Legends properties in code behind as shown bellow steps.
                Chart1.Legends["Default"].Title = "Chart";
                Chart1.Legends["Default"].LegendStyle = LegendStyle.Column;
                Chart1.Legends["Default"].Docking = LegendDocking.Right;
                Chart1.Legends["Default"].Alignment = StringAlignment.Center;
                Chart1.Legends["Default"].BackColor = System.Drawing.Color.Transparent;
                Chart1.Legends["Default"].IsTextAutoFit = false;
                Chart1.Legends["Default"].BorderColor = Color.Black;
                Chart1.Legends["Default"].BorderWidth = 2;
                Chart1.Legends["Default"].BorderDashStyle = ChartDashStyle.Solid;
                Chart1.Legends["Default"].Font = new Font("Arial", 10, FontStyle.Bold);
                Chart1.Legends["Default"].ForeColor = Color.Black;
                Chart1.Legends["Default"].IsEquallySpacedItems = true;


We can set Legends properties in Design 

<Legends>
     <asp:Legend Name="Legend1" Docking="Right" Title="Chart" ForeColor="Black" BorderColor="Black" BorderWidth="2"  BorderDashStyle="Solid" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"  IsTextAutoFit="False">
     </asp:Legend>
</Legends>

05 April 2012

Comparing ListView with GridView,DataList and Repeater

ASP.NET 3.5 introduces a new data binding control named the ListView. ASP.NET already has a lot of data bind controls; it should be more than 10. But the good news is, ListView can literally replace all other data binding controls in ASP.NET. ListView control makes data binding easier than previous controls. It has included styling with CSS, flexible pagination, and sorting, inserting, deleting, and updating features.

  1. A very flexible and customizable layout.
  2. A built in data paging support with the new DataPager control.
  3. Support data grouping (repeating items) in a flexible way.
  4. Built in support for deleting,inserting,paging,sorting,and updating the data.
Now , to compare the ListView control with the dataList,GridView and repeater control , lets look at the table below : 

Supported Funcationalities
ControlPagingData GroupingProvide Flexible LayoutUpdate,DeleteInsertSorting
ListViewsupportedsupportedsupportedsupportedsupportedsupported
GridViewsupportedNot supportedNot SupportedsupportedNot Supportedsupported
DataListNot supportedsupportedsupportedNot supportedNot supportedNot supported
RepeaterNot supportedNot supportedsupportedNot supportedNot supportedNot supported
* Supported: means that it's provided out of the box without any custom code or hacks.
* Not Supported: means that it's not provided out of the box by the control but it could be possible to implement it using custom code \ hacks.
The GridView : it supports paging but it doesn't provide a flexible layout , since its mainly used to display the data in a table based layout.And If we looked at data inserting , the Gridview doesn't have a built in support for inserting data( since it doesn't call the insert method of it underlying data source when you click on a button with a CommadName set to "Insert" ).
The DataList : it support data grouping ( through its RepeatColumns property) , but it doesn't have a built in support for paging,inserting ,deleting , updating the data. and if you looked at its laout , you will find that by default  the datalist renders as html table and you will have to set its flowLayout to "Flow" to stop that behaviour.
The Repeater control : you will find that it provides a flexible layout but it doesn't support data grouping ,inserting,deleting , updating  and paging through the data .

31 March 2012

Convert String to Number in Crystal Reports

Use a Crystal formula to convert string field to Number by using the ToNumber function.
Example: 
ToNumber({Table.Column})


To convert any Numeric field to Text by using the ToText function.
Example:
ToText({Table.Column})
This will allow you to use String functions (i.e. Mid, Left, etc) on any Numeric field.

Hide fields in Crystal Report

To hide any formula value or field values.  Select field and right click on it then context menu displays select Format Editor as shown below screen shots.
Step 1:
Step 2: