Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 28th, 2008, 11:43 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridView values to Word

Hi Friends,

i've a problem so , i've a GridView showing questions from database(i've a SqlDataSource and i bind the data to the control from the stored procedure) like the following :

ID QUESTION LETTER CONTENT
1 Ghjjkllllll A,B,C,D,E Aaa,bbb,ccc,ddd,eee
2 dfhjsdh A,B,C,D,E Fff,ggg,hhh,iii,jjj


i want to take this question and choices and to transfer to a WORD document like the following style :

1)Ghjjkllllll
 A)Aaa
 B)bbb
 C)ccc
 D)ddd
 E)eee

2)dfhjsdh
 A)Fff
 B)ggg
 C)hhh
 D)iii
 E)jjj

i can transfer questions to the word document but choices... i couldnt do it ..!

what can i do? Help me

  #2 (permalink)  
Old February 28th, 2008, 05:00 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

What you are probably going to have to do is use an HTMLWriter / Table to format the information the way you want.

Your psuedo-code is something like:

//declare table object to be exported to word
//retrieve datasource
//for each row in datasource
     //create new TableRow
     //create new TableCell
        //append data to TableCell
     //add TableCell to TableRow
     //add TableRow to Table
//loop

then to ultimately write the code to the browser you would do something like this:
       System.IO.StringWriter sw = new System.IO.StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        Response.Clear();
        Response.AddHeader("content-disposition", "attachment;filename=test.doc");
        Response.ContentType = "application/vnd.word";

        tbl.RenderControl(hw); //this is your Table object
        Response.Write(sw.ToString());
        Response.End();

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
  #3 (permalink)  
Old February 29th, 2008, 06:59 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but i want to transfer this values without table

besides how can i parse Letter and Content Column's values like this

A) aaa
B) bbb
C) ccc
D) ddd
E) eee

  #4 (permalink)  
Old February 29th, 2008, 09:17 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

As far as I know, one way or the other, you will end up sending some sort of Table to word. That doesn't necesscarily mean the data will be in a tabular format though.

In any event to get the format that you want you would ultimate loop your data source and then split both your Question and Content columns on , you would then loop the resulting string arrays to place the data into the table.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========


Similar Threads
Thread Thread Starter Forum Replies Last Post
HyperLink in a gridview contro to open word docmen Otoniel ASP.NET Espanol 0 October 7th, 2008 01:11 AM
Exporting GridView to MS word sureshbabu C# 2005 0 August 29th, 2008 05:39 AM
How to retrieve values from gridview rojiin ASP.NET 2.0 Basics 1 June 26th, 2007 07:32 AM
Calculating Gridview Column Values rit01 ASP.NET 2.0 Professional 1 October 18th, 2006 03:46 PM
how to hide Field values in Gridview KamalRaturi ASP.NET 2.0 Professional 1 August 26th, 2006 11:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.