ali raza

C#, .Net ,Asp.net and my thoughts

Monthly Archives: August 2008

The IT Crowd

last day at lunch break, boss told me british tv show “The IT crowd”. I download some its epsoides from net. Really enjoy the life at IT support.  You love to Watch IT, not “it” it is “I-T”. Life at pepsi-cola lahore is not much different form it.

url http://www.channel4.com/entertainment/tv/microsites/I/itcrowd/

how to get server.mappath in c# class

i face a problem that server.mappath did not available in c# class at my utillity framework at app code folder of one of my asp.net application.  While it is available at asp.net page code behind.  Because ASP.NET pages contain a default reference to the System.Web namespace (which contains the
HttpContext class), you can reference the members of HttpContext on an .aspx
page without the fully qualified class reference to HttpContext.

For using Server.MapPath at C# class i used it following

System.Web.HttpContext.Current.Server.MapPath(logpath);

how to change the color of datagridviews row at difference in two dates

use the following Code in application

//This method returns the no of days between today and date comes from database
private int GetDateDifference(DateTime _StartDateTime )
{
DateTime startDate = _StartDateTime;
// End date
DateTime endDate = DateTime.Now;
// Time span
TimeSpan diffDate = endDate.Subtract ( startDate );

return diffDate.Days;
}
//Gridview Row Data Bound Event
protected void grdDetail_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType != DataControlRowType.Header && e.Row.RowType != DataControlRowType.Footer )
{

Label _lbl = (Label)e.Row.FindControl("lblDate");

if (_lbl != null)
{
_lbl.Text = DataBinder.Eval(e.Row.DataItem, "TRANSACTION DATE").ToString();
int intDays = GetDateDifference(Convert.ToDateTime(DataBinder.Eval(e.Row.DataItem, "TRANSACTION DATE")));
if (intDays > 2)
{
// Setting the color of row
e.Row.BackColor = System.Drawing.Color.Red;
}
}
}

Enjoy

how to clear controls in asp.net c#

Use following code in you page. At Calling Statement send reference of page “this”. It Clears all text boxes and set all checkboxes on page to false

private void ClearControls(Control parent)
{
foreach (Control _ChildControl in parent.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
ClearControls(_ChildControl);
}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Text = string.Empty;
}
else
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Checked = false;
}

}
}
}