hi gndzkdr,
use this code for exporting data into xls
file.You
need to reference a dll file for this
that you can get at following link
http://www.codeproject.com/aspnet/ExportClassLibrary.asp
when you download any project then you will get rklib......
dll .Use
this
private void Page_Load(object sender, System.EventArgs e)
{
try
{
lblError.Text = "";
if (!IsPostBack)
{
get_AllEmployees( );
Session["dsEmployee"] = dsEmployee;
dgEmployee1.DataSource =
dsEmployee.Tables["Employee"];
dgEmployee1.DataBind();
dgEmployee2.DataSource =
dsEmployee.Tables["Employee"];
dgEmployee2.DataBind();
dgEmployee3.DataSource =
dsEmployee.Tables["Employee"];
dgEmployee3.DataBind();
}
}
catch(Exception Ex)
{
lblError.Text = Ex.Message;
}
}
private DataSet get_AllEmployees()
{
try
{
// Get the employee details
string strSql = "SELECT EmployeeID, LastName,
FirstName,
Format(BirthDate, 'dd-MMM-yyyy') As BirthDate,
Format(HireDate,
'dd-MMM-yyyy') As HireDate, Address, PostalCode FROM
Employees";
OleDbConnection objConn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" +
Server.MapPath("Database\\Employee.mdb"));
OleDbDataAdapter daEmp = new OleDbDataAdapter(strSql,
objConn);
daEmp.Fill(dsEmployee, "Employee");
return dsEmployee;
}
catch(Exception Ex)
{
throw Ex;
}
}
private void btnExport2_Click(object sender,
System.EventArgs e)
{
// Export the details of specified columns
try
{
// Get the datatable to export
DataTable dtEmployee = ((DataSet)
Session["dsEmployee"]).Tables["Employee&q
uot;].Copy();
// Specify the column list to export
int[] iColumns = {1,2,3,5,6};
// Export the details of specified columns to Excel
RKLib.ExportData.Export objExport = new
RKLib.ExportData.Export("Web");
objExport.ExportDetails(dtEmployee, iColumns,
Export.ExportFormat.Excel,
"EmployeesInfo2.xls");
}
catch(Exception Ex)
{
lblError.Text = Ex.Message;
}
}
Thanks & Regards,
Gagan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|