printing a datagrid

G

Guest

i have a c# asp.net webform that contains a datagrid. the datagrid has a
vertical scroll. i need to give the user the ability to print the datagrid's
entire content (all the rows). IE's print menu prints only the rows that are
currently shown. thanks in advance.

string sqlcmd = sqlSelect + sqlOrder;
DataSet ds = new DataSet();
OracleConnection oraConn = new OracleConnection(connStr);
OracleCommand oraCMD = new OracleCommand(sqlcmd, oraConn);
oraConn.Open();
OracleDataAdapter da = new OracleDataAdapter(oraCMD);
da.Fill(ds);
dgSearchResults.DataSource = ds.Tables[0];
dgSearchResults.DataBind();
dgSearchResults.Visible = true;

where dgSearchResults is the Datagrid
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

I had a similar problem so what I did was open a new window, copy the grid
content to it and just call window.Print(), here is the code:
//for the printing page:

<script>
function FillPage()
{
var div = document.all["CONTENT"];
var origdiv = window.opener.document.all["TextPanel"];

div.innerHTML = origdiv.innerHTML;


print();
//close();
}
</script>
</head>
<body MS_POSITIONING="GridLayout" onload="FillPage();">
<span id="CONTENT">
</span>



in the parent page just enclose the grid in a div named "TextPanel"


cheers,
 
G

Guest

thanks a lot.

Ignacio Machin ( .NET/ C# MVP ) said:
hi,

I had a similar problem so what I did was open a new window, copy the grid
content to it and just call window.Print(), here is the code:
//for the printing page:

<script>
function FillPage()
{
var div = document.all["CONTENT"];
var origdiv = window.opener.document.all["TextPanel"];

div.innerHTML = origdiv.innerHTML;


print();
//close();
}
</script>
</head>
<body MS_POSITIONING="GridLayout" onload="FillPage();">
<span id="CONTENT">
</span>



in the parent page just enclose the grid in a div named "TextPanel"


cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation




Newbie said:
i have a c# asp.net webform that contains a datagrid. the datagrid has a
vertical scroll. i need to give the user the ability to print the
datagrid's
entire content (all the rows). IE's print menu prints only the rows that
are
currently shown. thanks in advance.

string sqlcmd = sqlSelect + sqlOrder;
DataSet ds = new DataSet();
OracleConnection oraConn = new OracleConnection(connStr);
OracleCommand oraCMD = new OracleCommand(sqlcmd, oraConn);
oraConn.Open();
OracleDataAdapter da = new OracleDataAdapter(oraCMD);
da.Fill(ds);
dgSearchResults.DataSource = ds.Tables[0];
dgSearchResults.DataBind();
dgSearchResults.Visible = true;

where dgSearchResults is the Datagrid
 

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

Top