Gridview in asp.net

GridView was introduced with Asp.Net 2.0.GridView was introduced with Asp.Net 2.0.Repeater It was introduced with Asp.Net 1.0.
GridView Rendered as Table.Repeater Template driven.
GridView  Automatically generates columns from the data source.Repeater This features is not supported.
GridView Selection of row is supported. Repeater Selection of row is not supported.
GridView Editing of contents is supported.Repeater Editing of contents is not supported.
GridView Built-in Paging and Sorting is provided.Repeater You need to write custom code.
GridView Supports auto format or style features. Repeater This has no this features.
GridView Performance is very slow as compared to Repeater.Repeater This is very light weight and fast data control among all the data control.

Example:
Change the color of a row depending on whether the Doctor is Active or Inactive.

protected void grdDoc _RowDataBound(object sender, GridViewRowEventArgs e)
{   
{       
if (e.Row.RowType == DataControlRowType.DataRow)       
{           
if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) ||                        (e.Row.Cells[3].Text != ” “))           
{               
Char result = Convert.ToInt32(e.Row.Cells[3].Text);
           if (result == ‘Y’)
e.Row.BackColor = System.Drawing.Color.Aqua;               
else if (result ==’N’)
e.Row.BackColor = System.Drawing.Color.Cornsilk;           
}
    }   
}
}

Advertisements

readonly Vs const

A readonly field can be set multiple times within the constructor(s). Even if the value is set in two different chained constructors it is still allowed.

Const must be initialized at declaration time, readonly can be initialized on the constructor (and thus have a different value depending on the constructor used).

Constants are static by default

Deferred Execution Vs Immediate Execution

Deferred Execution:

In case of differed execution, a query is not executed at the point of its declaration. It is executed when the Query variable is iterated by using loop like as for, foreach.

Immediate Execution:

query is executed at the point of its declaration. The query which returns a singleton value (a single value or a set of values) like Average, Sum, Count..

Shallow copying Vs Deep copy

Shallow copying is creating a new object and then copying the non static fields of the current object to the new object. If the field is a value type, a bit by bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not.

Deep copy is creating a new object and then copying the non-static fields of the current object to the new object. If a field is a value type, a bit by bit copy of the field is performed. If a field is a reference type, a new copy of the referred object is performed.

Gridview in asp.net

GridView was introduced with Asp.Net 2.0.
Repeater It was introduced with Asp.Net 1.0.

GridView Rendered as Table.
Repeater Template driven.

GridView Automatically generates columns from the data source.
Repeater This features is not supported.

GridView Selection of row is supported.
Repeater Selection of row is not supported.

GridView Editing of contents is supported.
Repeater Editing of contents is not supported.

GridView Built-in Paging and Sorting is provided.
Repeater You need to write custom code.

GridView Supports auto format or style features.
Repeater This has no this features.

GridView Performance is very slow as compared to Repeater.
Repeater This is very light weight and fast data control among all the data control.

Example:

Change the color of a row depending on whether the Doctor is Active or Inactive.

protected void grdDoc _RowDataBound(object sender, GridViewRowEventArgs e)
{
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((string.IsNullOrEmpty(e.Row.Cells[3].Text) != true) ||
(e.Row.Cells[3].Text != ” “))
{
Char result = Convert.ToInt32(e.Row.Cells[3].Text);
if (result == ‘Y’) e.Row.BackColor = System.Drawing.Color.Aqua;
else if (result ==’N’) e.Row.BackColor = System.Drawing.Color.Cornsilk;
}
}
}
}

Application variables Vs Session variables

Application variables are the variables which remain common for the whole application for all the users.
Their value can be used across the whole application by any user.
And they die only when the application stops or probably when they are killed forcibly.
The ideal example for these kind of variables are site counter.

Session variables are variables which remain common for the whole application but for one particular user.
They also can be used across the whole application but each user will have a copy.
But they die when a particular user session ends or probably when they are killed forcibly
The ideal example for this kind of variable are user id… You might want to show “Welcome Prabha”.