StatCounter

View My Stats

Tuesday, February 5, 2008

Reduce the Bandwidth Suffer in .NET

Reduce the Bandwidth Suffer in .NET


While using a complex control like GridView, Repeater ,DetailsView control We have to Disable the ViewState.......Otherwise it degrades the Bandwidth of your connection.

To overcome this :
Page Load
if(!Page.IsPostBack)
{
BindGrid();
}

Instead of that use:(Directly BindGrid)
Page Load
BindGrid();

The disadvantages of this Method is the Evets of the controls like RowCommand Wont Work.Check this out Properly

Use directly at the Page Load. This al so the performance issue.But for comparing the above this give some better performance.

?? Operator in .NET

?? Operator in .NET


This operator is used to check whether the string is null or not.If is it null values we can set a Default value in it.


Example:
string a;//The default value of a is null

Page Load
{
a=a?? "Hi";
Response.write(a);
}

output: Hi // we set the default value of a is null

To Add Empty Row in DataTable in ADO.NET

To Add Empty Row in DataTable in ADO.NET


if ((Ds.Tables[0].Rows.Count == 0))
{
Ds.Tables[0].Rows.Add(Ds.Tables[0].NewRow());
}


Ds-DataSet Name that containes Tables

Create a DataTime With a user Specified Time

Create a DataTime With a user Specified Time


DateTime SlotEndTime =DataTime.Now;

SlotEndTime = new DateTime(SlotEndTime.Year, SlotEndTime.Month, SlotEndTime.Day, 9, 30, 0);

SlotEndTime -Have the Date of today with the Time-9.30 AM

Create a DataTime With a user Specified Time

DateTime Time1=DataTime.Now;

Time1= new DateTime(SlotEndTime.Year, SlotEndTime.Month, SlotEndTime.Day, 9, 30, 0);


The Time1- Field have Today date with the time 9.30 am

DateTime Comparison in .NET:

DateTime Comparison in .NET:


DateTime t1 = DateTime.Now;


DateTime t2 = Convert.ToDateTime("11:00:00 AM");


int i = DateTime.Compare(t1,t2);


//if t1 is less than t2 then result is Less than zero


//if t1 equals t2 then result is Zero


//if t1 is greater than t2 then result isGreater zero

DateTime Comparison in .NET:

DateTime t1 = DateTime.Now;

DateTime t2 = Convert.ToDateTime("11:00:00 AM");

int i = DateTime.Compare(t1,t2);

//if t1 is less than t2 then result is Less than zero

//if t1 equals t2 then result is Zero

//if t1 is greater than t2 then result isGreater zero