|
hi
i am using following code to export gridview to excel..but the generated excel file does not contain rows and columns as normal excel file ...
can any on e suggest a solution for that
here is my code
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
String savefile = heading;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + savefile + ".xls");
HttpContext.Current.Response.Charset = "";
gv.RenderControl(htw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
|
|
|
|
|
use the below code in you ExporttoExcel function
using conn as new SqlConnection(Constring)
conn.open()
da=new sqlDataAdapter(query,conn)
da.fill(ds)
End Using
Dim Gridview1 as New Gridview
Gridview1.datasource=ds
Gridview1.databind()
Response.clear()
Response.Buffer=true
Response.AddHeader("content-disposition","attachment;filename=testfile.xls")
Response.charset=""
Response.ContentType="application/vdn.ms-excel"
Dim sw as new StringWriter()
Dim hw as new HtmlTextWriter(sw)
For i as integer=0 To Gridview1.Rows.Count-1
Gridview1.Row(i).Attribute.Add("class","textmode")
Next
Gridview1.RenderControl(hw)
dim style as String="<style> .textmode(mso-number-format:\@;}</style>"
Response.write(style)
Response.output.write(sw.ToString())
Response.Flush()
Response.End()
Imtiaz A.K
|
|
|
|
|
thanks for reply
i am new in asp.net and unaware in vb.net
pls give me code in asp.net.
Thnaks a lot
|
|
|
|
|
It is in Asp.Net only...
When u write code in ASP.net, it means you have to choose the language you prefer to code either vb.net or C# etc..
the code which i have send is used in asp.net application only...
and if u are using the C# as code behind then.. convert this piece of code into c# as we have many online converters...
paste the code they will give converted format in C#...
Regards
Imtiaz
Imtiaz A.K
|
|
|
|
|
thanx
it works as it is I previously return code for this........
|
|
|
|
|
Have you tried earlier solutions?
|
|
|
|
|
|
<A NAME="Anyname"></A>Your Text
<A HREF="#Anyname">Click Here</A>
The above page link works fine on Firefox and doesn't work on IE.
On IE something like this works -
<A NAME="Anyname">Your Text</A>
<A HREF="#Anyname">Click Here</A>
but i don't want "Your Text" to appear as same font as link i.e. A tag and that is the reason i want to use
<A NAME="Anyname"></A>Your Text
Any ideas??
Andyyy
|
|
|
|
|
|
|
AndyInUK wrote:
<A NAME="Anyname"></A>Your Text
<A HREF="#Anyname">Click Here</A>
I have been using the above method only in my applications. It works perfectly in Internet Explorer as well as Firefox. Please check well whether you are missing something.
And also what version of IE are you using?
|
|
|
|
|
AndyInUK wrote: i don't want "Your Text" to appear as same font as link
Then use CSS, as in Cascading Style Sheets, to set the style.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi
i have given a small functionality of sliverlight based in my website but when the website launched in client system , client system not showing sliver light functionaliy because of sliver light is not installed. i need to know whether user can view the functionality with out installing sliver light.
|
|
|
|
|
Hi,
This is not possible.
Regards,
Jamil
|
|
|
|
|
This is officially a stupid question.
How can someone possibly view Silverlight content without having Silverlight installed?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Not a stupid question, but a reasonably stupid response. I suggest a closer reading of the question before commenting on it.
They want to test for Silverlight being installed, and therefore probably show some alternative content if it is not.
How many times have we all done a similar test for JavaScript enabled? Admittedly, usually to show a message telling the user to enable it.
|
|
|
|
|
Hi
thanks you understood my question, but i am sorry all if i didnt raised it in a manner.
|
|
|
|
|
Your welcome.
It had to be detection of silverlight installed because otherwise the question made no sense. But then we get a lot of questions here that don't make much sense.
Glad I could help.
|
|
|
|
|
You can test for it on the client side using JavaScript
One way to test is demonstrated here[^].
Basically you test for being able to create the AgControl.AgControl ActiveX Component:
if ((navigator.userAgent.indexOf('Windows') != -1) &&
(navigator.appVersion.indexOf('MSIE') != -1) )
{
try
{
var AgControl = new ActiveXObject("AgControl.AgControl");
agVersion = AgControl.settings.version;
AgControl = null;
}
catch (e)
{
agVersion = -1;
}
}
alert(agVersion);
Alternatively, this guide[^] shows best practice for testing for Silverlight and installing it if it is missing.
When referencing the Silverlight.js script you can then test the Silverlight.available property in your JavaScript to see if Silverlight is installed, and follow up with a call to Silverlight.isInstalled(version) to test for the correct version.
I can't see any way of detecting Silverlight on the client when running server-side code.
|
|
|
|
|
I hope somebody can help me with this.
I have got this DataGrid, with a buttoncolumn, and my problem is that depending on the language the user has chosen, it should show one text, or another.
The language is saved on Session=("language"), it can be "EN" English, or "ES" Spanish.
So, how could I write this column?
I tried this:
<asp:ButtonColumn Text="<% if Session("language") = "ES" then Response.Write ("Editar") else ("Edit") end if %>" CommandName="Select">
I get an error.
Error 1 The literal content ('<asp:ButtonColumn Text="') is not allowed in 'System.Web.UI.WebControls.DataGridColumnCollection'.
(The error message is translated to English, it is not probably the real text)
|
|
|
|
|
Hi,
you can you use the DataBound event of the grid to set the text of the button, but the best practice is to set the UI culture by overriding the following event in your page:
protected override void InitializeCulture()
{
System.Threading.Thread.CurrentThread.CurrentUICulture = "the culture";
System.Threading.Thread.CurrentThread.CurrentCulture = "the culture";
}
Regards,
Jamil
|
|
|
|
|
Thanks for answering Jamil.
I'm sorry, I don't know anything about what you say, that UI Culture thing...
And when you say Databound, doy you mean databinding? I don't see any databound event on the grid, just data binding.
I'm using VS2005, by the way.
Thanks in advance.
PS: How could I complete the code?
datagrid.columns(i).text = "ES"
There is no text property on columns collection.
|
|
|
|
|
Hi,
Iam developing a intranet site and want to track the users, iam using session for this purpose, Iam using windows authentication mode so there is no login form here..
when a user clicks the url for the first time a new session is created and at that time Iam adding a entry in a table(say :Users) with username and logintime and sessionid etc.,
Below is the logic Iam using in form_load event of Default.aspx
If session("user") is nothing then
---create new session (at this point Iam adding a entry in table(users))
Else
--- use the same session and continue the work.
End if
When i check the users in the table some entries are created with same userid and same sessinids with different login time, how this is possible...
could someone explain, why this is happening..
Regards
Imtiaz A.K
|
|
|
|
|
Khaja A. Imtiaz wrote: When i check the users in the table some entries are created with same userid and same sessinids with different login time, how this is possible...
It means, you are not clearing Session Value when user logging off from application and not updating the database also.
|
|
|
|
|
Iam clearing the session when user is logged off..
Below is the code used when user logged off..
session.removeAll()
session.abandon()
If Iam not clearing the sessions, then as per my logic in the Page_load, it should not add a entry in the table instead it should perform the other work without adding entry.
since Iam using the below code in Page_load of Default.aspx
If session("user") is nothing then
---create new session (at this point Iam adding a entry in table(users)
Else
--- use the same session and continue the work.
End if
when Iam doing certain tests.. iam not facing any such issues, but when the users are working on this portal.. I can see these kind of issues...
What could be the problem, please suggest.
Regards
Imtiaz A.K
|
|
|
|