Printing a report from a datagrid.

M

Mattyw

Hi,

I am relatively new to Visual Studio.NET (i am using VB), I have
created a datagrid which I have bound to a SQL database, when I browse
the form with the datagrid it displays all the columns as expeced using
the following code:

If Not IsPostBack Then
SqlConnection1.Open()
Dim Reader As SqlClient.SqlDataReader
Reader = SqlCommand1.ExecuteReader()
DataGrid1.DataSource = Reader
DataGrid1.DataBind()
Reader.Close()
SqlConnection1.Close()

I now want to be able to select a row, either by clicking a checkbox
(if it's possible to add a checkbox to a datagrid) or using the select
button and then display the data from that row in a new page in a
format that is printable, I just need to know how to launch the
selected item in the datagrid to a new page. I'm pretty sure I'll be ok
with populating the new page with the data using labels, then having a
print button to print the page.

Any help would be appreciated.

Matt.
 
E

Elton Wang

Hi Mattyw,

The easy way is to add a ButtonColumn to the datagrid and
manipulate data process in datagrid_ItemCommand event. In
the event, you can use e.Item.Cells(colIndex).Text to
collect data for each column in the selected (clicked)
row. Or since you want to process the data in a new page,
you can save the e.Item (DataGridItem) in SessionState. In
the process page, you can retrieve the DataGridItem from
SessionSate, and get data from the DataGridItem.


HTH

Elton Wang
(e-mail address removed)
 
G

Guest

Mattyw said:
Thanks for the input, I've added the button column to my datagrid, I
think the best result would be to launch a new page on the button
click, then passing the columns datafields to labels in the new page so
that they can be printed, will a button_click event handler be required
or can a new page be launched from using the selecteditem?

Apoligies for my lack of programming experience but I am an
Administrator by trade!.

Hi, the ASPNET quickstart at http://www.asp.net/Tutorials/quickstart.aspx
will show u how to do this, look under Web Form Controls Reference and the
DataGrid section. Specifically the VB DataGrid3.aspx example.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top