Change RadGrid row color

If e.Item.ItemType = GridItemType.AlternatingItem OrElse
e.Item.ItemType = GridItemType.Item Then

If CInt(RCB_InvoiceType.SelectedValue)
= 2 Then

If TypeOf
e.Item Is GridDataItem

Dim dataItem As
GridDataItem = CType(e.Item, GridDataItem)

Dim dueDays As
TableCell = dataItem(“DueDays”)

If CDec(dueDays.Text)
> 0 Then

dataItem.ForeColor = Drawing.Color.Red

End If

End If


End If

End If

DataTable vs List

Recently just make in depth research about DataTable. DataTable is easy to use variable which allows user to pool data into it with consistence format, embed with other properties that allow us to do sorting, search etc. Currently I am researching on high performance application, which need to store large amount of data into memory. Soon I hit a bottleneck with DataTable. When inserting more than 5 million of records into DataTable, my desktop starts to struggle, even with 5G Ram So I need to find an alternative.
  The main purpose of my tool  is analyzing large amount of data. It uses to compare ID and do heavy calculation on selected field. After do some research, I found list can on par with DataTable’s needed function, at the same time increase efficiency.
So lets prove it!
DataTable button click event
private void button3_Click(object sender, EventArgse)
            Stopwatch stopwatch = new Stopwatch();
            DataTable dt = new DataTable();
            long i = 0;
            while (i < 1000000)
                dt.Rows.Add(“a” + i.ToString(),”b” + i.ToString(), “c” + i.ToString(), “d” + i.ToString(),”e” + i.ToString());
List button click event
private void button4_Click(object sender, EventArgse)
            Stopwatch stopwatch = new Stopwatch();
            List<List<lst>> lists = newList<List<lst>>();
            long i = 0;
            while (i < 1000000)
                List<lst> list = new List<lst>();
                lst superlist = new lst
                    field1 = “a” + i.ToString(),
                    field2 = “b” + i.ToString(),
                    field3 = “c” + i.ToString(),
                    field4 = “d” + i.ToString(),
                    field5 = “e” + i.ToString()
        class lst
            public string field1 { get; set; }
            public string field2 { get; set; }
            public string field3 { get; set; }
            public string field4 { get; set; }
            public string field5 { get; set; }
Benchmark result:
datatable memory usage
list memory usage
time taken in milisecond, for DataTable
time taken in milisecond, for List
List is 4X faster then datatable
DataTable uses 6X more memory then list

Difference Between Union vs. Union All

The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.

A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.

Run following script in SQL Server Management Studio to see the result between UNION ALL and UNION. Download complete script from here.

/* Declare First Table */
DECLARE @Table1 TABLE (ColDetail VARCHAR(10))
SELECT 'First'
SELECT 'Second'
SELECT 'Third'
SELECT 'Fourth'
SELECT 'Fifth'
/* Declare Second Table */
DECLARE @Table2 TABLE (ColDetail VARCHAR(10))
SELECT 'First'
SELECT 'Third'
SELECT 'Fifth'
/* Check the data using SELECT */
FROM @Table1
FROM @Table2
FROM @Table1
FROM @Table2
/* UNION */
FROM @Table1
FROM @Table2

In our example we have two tables: @Table1 and @Table2.

Now let us run UNION ALL and UNION together and see the resultset as well as Execution Plan compared to complete set of query. You can always turn on actual execution plan using CTRL+M.

We can see from the resultset of UNION ALL that it returns everything from both the table but from UNION it is very clear that only DISTINCT rows from both the table is only retrieved.

Additionally, when comparing the execution plan of UNION ALL and UNION it is also quite clear that UNION ALL is way less expensive than UNION as it does not have DISTINCT SORT operation.

Let me know what do you think about this article. If you have any suggestion for improvement please let me know and I will update articles according to that.

Reference : Pinal Dave

Significant differences in Array vs Array List

Array (A System namespace) is a datatype, that can be used by calling indexes. during runtime, one cannot really change the size of the array, unless you use the method of copying the array and getting rid of the old one.

In .NET, the Visual Studio makes use of a special class to store the data. Because of this, the performance is actually quite fast. This is also because in an array, you need to specify the size and thus, the data is stored one after the other.


int[] myNumbers=newint[5];

ArrayList (System.Collections namespace) is a datatype collection. In order to fill an ArrayList, one can use the .Add property. ArrayLists are very dynamic in the sense that when you add and/or remove items from it, the performace stays the same.

The internal structure of an ArrayList is an array.


ArrayList myArray =newArrayList();
myArray.Add(“Steph”);string str = myArray[0];

Most of the time, we tend to choose array lists rather than arrays since we have no idea how big it is going to turn out. Arrays are ideal when you know how many items you are going to put in it. Whenever possible, it is recommended to use arrays as this drastically improves the performance.

Array are sequence of homogeneous data while ArrayList is sequence of heterogenous data. That’s why we have to typecast every data in ArrayLists.

Arrays are multidimensional but ArrayList is always single-dimensional.

Arrays are strongly typed, and work well as parameters. If you know the length of your collection and it is fixed, you should use an array.

ArrayLists are not strongly typed, every Insertion or Retrial will need a cast to get back to your original type. If you need a method to take a list of a specific type, ArrayLists fall short because you could pass in an ArrayList containing any type. ArrayLists use a dynamically expanding array internally, so there is also a hit to expand the size of the internal array when it hits its capacity.

Cross tab query with PIVOT

Many times developer has an issue while writing query with PIVOT. Let me have a sample code for query with PIVOT keyword.

PIVOT is used to transform rows to column, which gives result in such a way which can be send to the user directly. Let me take an example. We have an order table where we have each order stored in a row in a table as displayed below:

ctrl_no id Amount OrderDate
1000029 100016 990 10/25/2012
1000029 100018 990 10/25/2012
1000029 100016 660 10/26/2012
1000029 100018 660 10/26/2012
1000029 206007 660 10/26/2012
1000029 206007 660 10/27/2012

This information has to be saved in a row in relational database. When this information needs to be display it on the application, it needs to be displayed as below, so user can use this info for decision making:

id 10/25/2012 10/26/2012 10/27/2012
100016 990.00 660.00 NULL
100018 990.00 660.00 NULL
206007 NULL 660.00 660.00

Did you see the difference? how easy user can review the information. Lets see an query how to achieve the expected result with PIVOT keyword.

CREATE TABLE #TestTable(ctrl_no INT, id int, Amount NUMERIC(18,2), OrderDate DATE)

INSERT INTO #TestTable(ctrl_no , id , Amount , OrderDate )
SELECT 1000029,100016,990.0000,'10/25/2012'
SELECT 1000029,100018,990.0000,'10/25/2012'
SELECT 1000029,100016,660.0000,'10/26/2012'
SELECT 1000029,100018,660.0000,'10/26/2012'
SELECT 1000029,206007,660.0000,'10/26/2012'
SELECT 1000029,206007,660.0000,'10/27/2012'

SELECT    id,
    SELECT    id,
    FROM #TestTable t
) x
    SUM(Amount) FOR OrderDate IN([10/25/2012],[10/26/2012],[10/27/2012])
) p
 DROP TABLE #TestTable


Slice image CSS. / Single file multiple images.

<!DOCTYPE html>
<style type=”text/css”>
#navlist li{margin:0;padding:0;list-style:none;position:absolute;top:0;}
#navlist li, #navlist a{height:44px;display:block;}
#home{background:url(‘img_navsprites_hover.gif’) 0 0;}
#home a:hover{background: url(‘img_navsprites_hover.gif’) 0 -45px;}
#prev{background:url(‘img_navsprites_hover.gif’) -47px 0;}
#prev a:hover{background: url(‘img_navsprites_hover.gif’) -47px -45px;}
#next{background:url(‘img_navsprites_hover.gif’) -91px 0;}
#next a:hover{background: url(‘img_navsprites_hover.gif’) -91px -45px;}
<ul id=”navlist”>
  <li id=”home”><a href=”default.asp”></a></li>
  <li id=”prev”><a href=”css_intro.asp”></a></li>
  <li id=”next”><a href=”css_syntax.asp”></a></li>

Difference between static variable and application variable

Static Variables

1. Variables defined local to a function disappear at the end of the function scope. So when we call the function again, storage for variables is created and values are reinitialized.

2. So if we want the value to be extent throughout the life of a program, we can define the local variable as “static.” Initialization is performed only at the first call and data is retained between func calls.

3. Static variables are local in scope to their module in which they are defined, but life is throughout the program. Say for a static variable inside a function cannot be called from outside the function but is alive and exists in memory.

Application Variables
1. Global Variables are also similar to the static variables but these variables are available outside the module/function and its scope is available through out the application.

2. These Variables can be accessed from any of the function

Enable/Disable RequiredFieldValidator with Javascript

 ValidatorEnable(document.getElementById("RequiredFieldValidator1"), true);
 ValidatorEnable(document.getElementById("RequiredFieldValidator2"), false);

 ValidatorEnable(document.getElementById("RequiredFieldValidator1"), false);
 ValidatorEnable(document.getElementById("RequiredFieldValidator2"), true);