|
Hi All,
I need Export the gridview to excel.When I click the Export button it should open the save dailog and user should give file name and path or it should take the filename with path. Anyway will do and it is save there.
Thanks in advance...
|
|
|
|
|
GridView does not have direct functionality to export data into Excel, so you would need to add extra efforts on your side to do this job.
There are several ways to export data into Excel and preserve format
1. Use Jet OLEDB Provider. You need to create INSERT SQL statements and loop through the rows of the grid to insert records one by one. But in this case you need to convert your column from numeric data type to string one.
2. Use Microsoft Office Tools for .NET. This way is slower, but gives you more functionality and allows formatting of the data. It allows you to control your output, but could be very slow and you need to pay attention to releasing all the resources associated with it, because it is COM-based.
3. Write code that stores data into CSV or HTML. Those formats recognized by Excel and should preserve formatting
4. Use third party components like Ajax, that could provide desired functionality
Regards,
Satips.
|
|
|
|
|
Hi Satips,
Thanks for the reply.
I got some code from Google.Its working fine.The only thing is that I need to save it on the server and filename should be given by me not by user.Following is the code:
On Export Button Click:
Dim attachment As String = "attachment; filename=Contacts.xls"
Response.ClearContent()
Response.AddHeader("content-disposition", attachment)
Response.ContentType = "application/ms-excel"
Dim sw As StringWriter = New StringWriter()
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
gvExport.RenderControl(htw)
Response.Write(sw.ToString())
Response.End()
This throws HttpException so I need to add this:
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
Now I just need to save it on server.
Can u please tell how do I do??
Thanks in advance...
|
|
|
|
|
hi,
just gothrough this link for popluating data from dataset to Excel sheet
|
|
|
|
|
Sorry No link found
|
|
|
|
|
see this link
ok
www.msdn2.microsoft.com/en-us/library/aa159891(office.11).aspx
|
|
|
|
|
sorry page cannot be displayed.......
|
|
|
|
|
http://msdn2.microsoft.com/en-us/library/aa159891(offices.11).aspx
|
|
|
|
|
plz explain .dll hell in .net
|
|
|
|
|
plz refer this link..
http://en.wikipedia.org/wiki/DLL_hell
In computing, DLL hell is a phrase for complications which arise when working with dynamic link libraries, or DLLs.
DLL hell encompasses the difficulties of managing dynamic-link libraries (DLLs) in Microsoft Windows operating systems. These difficulties include conflicts between DLL versions, difficulty in obtaining required DLLs, and having many unnecessary DLL copies.
|
|
|
|
|
|
hi guys
i would like to retrive the data of One cell of the sql database's table
i already know the command will be like this:
select age from kids where nric = 'sss'
this command statement would retrive only 1 result
however i dont know the sysntex to use this command statment with in asp.net (c# coding side)
could anyone show me how it is done pls?
|
|
|
|
|
sqlconnection conn = new sqlconnection(path of the connection);
sqlcommand cmd = new sqlcomand("your query", connection);
string result;
result=cmd.executescalar();
Gautham
|
|
|
|
|
it says
Error 51 The type or namespace name 'sqlconnection' could not be found (are you missing a using directive or an assembly reference?)
|
|
|
|
|
be sure to import System.Data.SqlClient NameSpace
Tirtha
Miles to go before I sleep
|
|
|
|
|
i already added
using System.Data.SqlClient;
if this is not correct pls kindly describe what i shld do pls
|
|
|
|
|
hi ..
here is some code for connecting to database..
i think this would help you.. make necessary changes..
this is just to show you how we can connect to the db..
put connection string in web.config file
using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public class dbClass
{
private SqlConnection con;
private SqlCommand com;
private SqlDataReader dr;
private SqlDataAdapter da;
private DataSet ds;
public dbClass()
{
con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conString"].ToString());
}
///
/// Open an Sql connection.
///
/// <returns>sqlconnection
public SqlConnection GetConnection()
{
try
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
}
catch (Exception ex)
{
string err = ex.Message.ToString();
}
return con;
}
///
/// Executes a query with SqlDataAdapter
///
/// <param name="sql" />sql query
/// <returns>DataTable
public DataTable GetAdapter(string sql)
{
try
{
com = new SqlCommand(sql, GetConnection());
com.CommandTimeout = 0;
da = new SqlDataAdapter(com);
ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
finally
{
con.Close();
}
}
|
|
|
|
|
hi
u can see this code and do it
string strCmd="select age from kids where nirc='sss'";
Sqlcommand cmd =new sqlCommand(strCmd,con);
cmd.CommandType=CommandType.Text;
con.open();
DataReader dr=cmd.ExecuteReader();
while(dr.read)
{
// code to populate data
example u want to populate to combo box then u can writecode like this
cmdAge.add.item(dr.GetValues[1]);
}
try with this code i hope u will come out of the problem
tell me confirm once
ok
|
|
|
|
|
actually in my web.config i already have an connection string called
HASDBConnectionString1
what i basically need is ONE value(int) while using the HASDBConnectionString1 connectionstring name in my web.config
my query is queryed by the key column so it always retrun only 1 value
i am using asp.net2 (2005) and sql server 2005
|
|
|
|
|
What is the difference between heap and managed heap.
|
|
|
|
|
A heap is a memory area that a memory manager uses for allocating memory.
The managed heap is the heaps (four of them) that the memory manager in .NET uses to allocate memory for managed objects.
If you allocate unmanaged memory from within .NET, it's allocated from the Windows heap instead of the managed heap. The .NET memory manager allocates memory from the Windows heap to use for the managed heap.
---
single minded; short sighted; long gone;
|
|
|
|
|
How can .net support multiple languages?
plz describe answer for this
|
|
|
|
|
I'm new to the mobile web application development.. I have developed a web application from which a user can select a .cab file to download to the mobile. I just want to know the steps for downloading a particular file to the mobile.Could anybody help me by giving me the proper guidance for the same..
[ I'm using ASP.net 2.0 with C#]
|
|
|
|
|
Hi All,
I need to display Sr No in GridView, in dataset I dont have Sr No column.Please tell me how do I do this...
Thanks in advance...
|
|
|
|
|
two things can be done...
1.Make an Autogenerate column in your Database table if your query doesnt include any JOINING......i.e if you are fetching record from 1 table....
2.If the case is not so...then u have to make 1 column in your DataSet table
....i.e u have to make a customized dataset from your existing dataset.....
Tirtha
Miles to go before I sleep
|
|
|
|