.Net, ASP.Net, C#, VB.net, SQL Server, Xml, CSS, Design Patterns related tips, tricks, code snippets, articles, links, thoughts, etc. from Binu & Subi Thayamkery.

Binu Thayamkery is a seasoned software architect with more than 13 years of experience in developing enterprise grade connected systems using Microsoft Technologies. In his current position as a lead consultant-solution architect with Prudential Financial, he is working on architecture of next generation investment reporting framework using .net 3.5/WCF/AJAX, etc. He holds a Masters Degree in Computer Science from Colorado State University. Subi Thayamkery is an experienced software developer with more than 8 years of developing various application software systems ranging from workflow automation systems to compliance management tools. She currently works as a technology consultant for Prudential Financial where she helps develop a new system for corportate governance department. She holds an Electrical Engineering degree from New Jersey Institute of Technology.

Monday, October 23, 2006

Create a Printer friendly page for DataGrid

For one of my projects, user needed a feature where they could print out their search results (shown in a datagrid). The following steps builds a printer-friendly page for datagrid results.

1. Add a new aspx page, call it Print.aspx
2. Add javascript to trigger IE print, on body load,


--body onLoad= "self.print()" --





--body--


3. Now comes the data, pass the underlying datasource for the grid to this page (use the method you like, use a session variable (bad), use a unique keyed cache item (ok), get it from parents property (good). Once you have this data, the following code block does the trick. Key is the RenderControl method of datagrid. It uses a HtmlTextWriter object to write out the HTML snippet of the grid. If we create the grid with plain vanila settings for color and edges, it will be "printer friendly".

On Page load add (don't forget to pass the dataview,

Response.Write(CreatePrinterFriendlyPage(dview).toString());


private StringBuilder CreatePrinterFriendlyPage(DataView dv)
{

DataGrid dg = new DataGrid();
dg.DataSource = dv;
dg.HeaderStyle.Font.Name = "Arial";
dg.HeaderStyle.Font.Bold = true;
dg.HeaderStyle.Font.Size = FontUnit.XSmall;
dg.ItemStyle.Font.Name = "Arial";
dg.ItemStyle.Font.Size = FontUnit.XXSmall;
dg.DataBind();

System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new HtmlTextWriter(tw);
dg.RenderControl(hw);

StringBuilder sb = new StringBuilder();
sb.Append (tw.ToString().Replace("\"","'").Replace("\r","").Replace("\n","").Replace("\t",""));

return (sb);

}


Happy coding !

Monday, October 02, 2006

System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.

I was trying to use OracleClient namespace for the first time, I wrote my first line of code...to try to connect to a Oracle db, and got this error!!
"System.Data.OracleClient requires Oracle client software version 8.1.7 or greater."
Misleading....beacuse I know that I have ver 9.2 installed!
Luckily, Google is there to help, issue is related to permissions! and the solution is goven in this good blog post by Roy Tore Gurskevik,
http://www.dotnetjunkies.com/WebLog/rtgurskevik/archive/2005/01/19/45958.aspx