Sunday, January 9, 2011

Export Excel From DataGrid using C#

Hi Guys.,
Using c# we need to Export To Excel from datagrid .Following Code will help For you


sample Code:

// create the DataGrid and perform the databinding
System.Web.UI.WebControls.DataGrid grid = new System.Web.UI.WebControls.DataGrid();
grid.HeaderStyle.Font.Bold = true;

DataSet ds = new DataSet();
ds.ReadXml("File Location");
grid.DataSource = ds.Tables[0];
//grid.DataMember = data.Stats.TableName;

grid.DataBind();

// render the DataGrid control to a file
using(StreamWriter sw = new StreamWriter(textBox1.Text))
{
using(HtmlTextWriter hw = new HtmlTextWriter(sw))
{
grid.RenderControl(hw);
}
}
}

Monday, January 3, 2011

usage of Global.axax in asp.net

Following Example will help for maintaining web application

Sample Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Diagnostics;

namespace DemoaboutGloabalasax
{
public class Global : System.Web.HttpApplication
{
// int visTeedCount = 0;
///
/// The Application Started it will fire
/// When the iis Start at the time it will fire
///

///
///
protected void Application_Start(object sender, EventArgs e)
{
EventLog.WriteEntry("Sample Application", "Application Started!", EventLogEntryType.Information);

}

protected void Session_Start(object sender, EventArgs e)
{
//visTedCount = visTedCount + visTedCount;
}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}

protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
///need to validate Active Directory User Details here
///
}

///
/// This Event Will fire When the application close
/// Ex: iisreset it will fire
///

///
///
protected void Application_End(object sender, EventArgs e)
{

EventLog.WriteEntry("Sample Application", "Application End at" + DateTime.Now.ToString() + "!", EventLogEntryType.Error);

}
}
}

now You can See all the details about your website in your web server using Event Viewer

1)when the Application Started(iis Started)
2)when the Application Stoped/Restarted(iis Reset)
3)what are the error's occurred in application at what time