Search This Blog
Friday, December 4, 2009
Print web page using JavaScript
{
if (navigator.appVersion.indexOf("IE 5.0")>=0 || navigator.appVersion.indexOf("IE 6.0")>=0)
{
var OLECMDID = 7;
/* OLECMDID values:
• 6 – print
• 7 – print preview
• 1 – open window
• 4 – Save As
*/
var PROMPT = 1; //note PROMPT = 2 -DO NOT PROMPT USER
var WebBrowser = ‘’;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
else
{
self.print();
}
}
Tuesday, December 1, 2009
How to display one group per page in a Crystal Report
GroupNumber <> PageNumber
After doing above, save the changes. Now it is ready to fulfill your requirement.
Thursday, November 12, 2009
How to use identity column in a SQL select statement
SELECT Userid,ServiceLineID,IDENTITY(int,1,1) AS i2
INTO #t
FROM users
ORDER BY ServiceLineID
SELECT * FROM #t
DROP TABLE #t
How to find width and height of an image using javascript
var newImg = new Image();
newImg.src = 'file://D:\image\img123.gif';
var height= newImg.height;
var width= newImg.width;
Friday, July 10, 2009
Internal SQL Server error
Internal SQL Server error.
if above error comes it means that you are missing
GROUP BY in inner query.
Thursday, July 9, 2009
Update a table from another table
UPDATE memodtl
SET type=y.type, origin=y.origin, Grade=y.Grade, length=y.length, width=y.width, thickness= y.Thickness, MemoQty=y.Nos
FROM podtl y
WHERE memodtl.memono=y.pono and memodtl.memodt=y.podt and memodtl.revNo = y.RevNo and memodtl.RecNo=y.ReCno and memodtl.SeqNo = y.SeqNo
Friday, June 12, 2009
How to bind gridview from dataset using XSLT
1:-XSLT file: Books.xsl
This is your XSLT file code
-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<books>
<xsl:apply-templates select="//book"/>
</books>
</xsl:template>
<xsl:template match="book">
<xsl:if test="price > 200">
<book>
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
<xsl:attribute name="specialization">
<xsl:value-of select="specialization"/>
</xsl:attribute>
<xsl:attribute name="author">
<xsl:value-of select="author"/>
</xsl:attribute>
<xsl:attribute name="publication">
<xsl:value-of select="publication"/>
</xsl:attribute>
<xsl:attribute name="price">
<xsl:value-of select="price"/>
</xsl:attribute>
</book>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--------------------------
2:-GridView Control
------------------------
add a gridview control in your web page with xmlDataSource as follows:
<asp:GridView ID="gvXML" runat="server" DataSourceID="XmlDataSource1">
<HeaderStyle BackColor="Gray" />
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" TransformFile="~/BindGridView.xsl">
</asp:XmlDataSource>
Note:This control always look data in <book name="ask" price="1220"> </book>
format
----------------------------
3:-C# code
Add this code in your Code-Behind file
--------------------------
SqlConnection myCon = new SqlConnection(@"data source=192.168.2.200\sql2k;uid=sa;pwd=bench;database=DMS1");
SqlDataAdapter da = new SqlDataAdapter("select name, price, specialization, author, publication from book", myCon);
DataSet ds = new DataSet();
ds.DataSetName = "books";
da.Fill(ds, "book");
xmlDataSource2.Data = ds.GetXml();
After doing the above steps you will get the following output
name | specialization | author | publication | price |
---|---|---|---|---|
ASP.Net 3.5 | Web Programming Using C# and VB | Bill Thomas | Wrox | 560.00 |
C# 3.5 | C# 2008 Powered by Microsoft | Microsoft Team | Wrox | 600.00 |
How to bind an xml datasource to a gridview
This is your xml document
-------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<books>
<book>
<name> Ajax 2.0 </name>
<specialization> Programming Language </specialization>
<author>Wiley ,Bill</author>
<publication>Wrox</publication>
<price>200.00</price>
</book>
<book>
<name> ASP.Net 3.5</name>
<specialization>Web Programming Using C# and VB </specialization>
<author>Bill Thomas</author>
<publication>Wrox</publication>
<price>560.00</price>
</book>
<book>
<name>C# 3.5 </name>
<specialization> C# 2008 Powered by Microsoft </specialization>
<author> Microsoft Team </author>
<publication>Wrox</publication>
<price>600.00</price>
</book>
</books>
-------------------------------
XSLT file: Books.xsl
This is your XSLT file code
-------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<books>
<xsl:apply-templates select="//book"/>
</books>
</xsl:template>
<xsl:template match="book">
<xsl:if test="price > 200">
<book>
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
<xsl:attribute name="specialization">
<xsl:value-of select="specialization"/>
</xsl:attribute>
<xsl:attribute name="author">
<xsl:value-of select="author"/>
</xsl:attribute>
<xsl:attribute name="publication">
<xsl:value-of select="publication"/>
</xsl:attribute>
<xsl:attribute name="price">
<xsl:value-of select="price"/>
</xsl:attribute>
</book>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
--------------------------
GridView Control
------------------------
add a gridview control in your web page with xmlDataSource as follows:
<asp:GridView ID="gvXML" runat="server" DataSourceID="XmlDataSource1">
<HeaderStyle BackColor="Gray" />
</asp:GridView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/books.xml" TransformFile="~/BindGridView.xsl">
</asp:XmlDataSource>
Note:This control always look data in <book name="ask" price="1220"> </book>
format
After doing the above steps you will get the following output:
name | specialization | author | publication | price |
---|---|---|---|---|
ASP.Net 3.5 | Web Programming Using C# and VB | Bill Thomas | Wrox | 560.00 |
C# 3.5 | C# 2008 Powered by Microsoft | Microsoft Team | Wrox | 600.00 |
How to tranform xml Document into html table using XSLT and C#
-------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<books>
<book>
<name> Ajax 2.0 </name>
<specialization> Programming Language </specialization>
<author>Wiley ,Bill</author>
<publication>Wrox</publication>
<price>200.00</price>
</book>
<book>
<name> ASP.Net 3.5</name>
<specialization>Web Programming Using C# and VB </specialization>
<author>Bill Thomas</author>
<publication>Wrox</publication>
<price>560.00</price>
</book>
<book>
<name>C# 3.5 </name>
<specialization> C# 2008 Powered by Microsoft </specialization>
<author> Microsoft Team </author>
<publication>Wrox</publication>
<price>600.00</price>
</book>
</books>
-------------------------------
XSLT file: books.xsl
------------------------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:element name="books">
<table >
<tr bgcolor="gray">
<td>Name</td>
<td>Specialization</td>
<td>Author</td>
<td>Publication</td>
<td>Price</td>
</tr>
<xsl:apply-templates select="//book" ></xsl:apply-templates>
</table>
</xsl:element>
</xsl:template>
<xsl:template match="book">
<tr>
<xsl:if test="price > 400">
<td width="100">
<xsl:value-of select="name"/>
</td>
<td width="100">
</td>
<td width="100">
<xsl:value-of select="author"/>
</td>
<td width="100">
<xsl:value-of select="publication"/>
</td>
<td width="100">
</td>
</xsl:if>
</tr>
</xsl:template>
</xsl:stylesheet>
-----------------------------
Step1:
add a literal control to the page like below:
<asp:Literal ID="ltr1" runat="server"></asp:Literal>
Step2:
C#
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
public partial class xmlTesting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
XPathDocument xPathDoc = new XPathDocument(Server.MapPath("books.xml"));
XslTransform xTrans = new XslTransform();
xTrans.Load(Server.MapPath("Books.xsl"));
StringWriter Sw = new StringWriter();
xTrans.Transform(xPathDoc, null, Sw);
ltr1.Text = Sw.ToString();
}
}
add a xml control to the page:
<asp:Xml ID="xml1" runat="server" DocumentSource="~/books.xml" TransformSource="~/Books.xsl"></asp:Xml>
-------------------------------------------------------------------
-------------------------------------------------------------------
name | specialization | author | publication | price |
---|---|---|---|---|
ASP.Net 3.5 | Web Programming Using C# and VB | Bill Thomas | Wrox | 560.00 |
C# 3.5 | C# 2008 Powered by Microsoft | Microsoft Team | Wrox | 600.00 |
Monday, June 8, 2009
How to handle: 'sys' is undefined.
<system.web>
<httphandlers>
<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false">
</add>
</httphandlers>
</system.web>
Saturday, June 6, 2009
Friday, June 5, 2009
javascript links
http://www.javascriptkit.com
http://www.w3schools.com
Thursday, June 4, 2009
Special Key and keyCode:
'esc':27,
'escape':27,
'tab':9,
'space':32,
'return':13,
'enter':13,
'backspace':8,
'scrolllock':145,
'scroll_lock':145,
'scroll':145,
'capslock':20,
'caps_lock':20,
'caps':20,
'numlock':144,
'num_lock':144,
'num':144,
'pause':19,
'break':19,
'insert':45,
'home':36,
'delete':46,
'end':35,
'pageup':33,
'page_up':33,
'pu':33,
'pagedown':34,
'page_down':34,
'pd':34,
'left':37,
'up':38,
'right':39,
'down':40,
'f1':112,
'f2':113,
'f3':114,
'f4':115,
'f5':116,
'f6':117,
'f7':118,
'f8':119,
'f9':120,
'f10':121,
'f11':122,
'f12':123’
}
Wednesday, May 6, 2009
How To execute a query string above 8000 chars
Declare @queryString1 varchar(8000)
Declare @Condition1 varchar(8000)
set @queryString1 =' ..any query string ... '
set @condition1=' ...any query condition....'
exec ('select [column]...... from Table_Name ......... '+ @queryString1 + @condition1)
Friday, April 24, 2009
Print Crystal Report(Server-Side)
// set 0 for all documents to print
crReportDocument.PrintToPrinter(1,false,0,0);
where crReportDocument is an object of ReportDocument and printername is the name of the printer.
Wednesday, March 18, 2009
How to select image from database
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandText = "SELECT * FROM [REPORT_TABLE]";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = _connectionString;
cmd.Connection = conn;
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd.CommandText, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = ds.Tables[0].Rows[0];
Byte[] b = (Byte[])dr["IMAGEFIELD"];
MemoryStream ms = new MemoryStream(b);
this.pictureBox1.Image = Image.FromStream(ms);
How To insert Image into database
string uploadFileName = string.Empty;
byte[] imageBytes = null;
if(imageUpload != null&& imageUpload.HasFile)
{
uploadFileName = imagUpload.FileName;
imageBytes = imageUpload.FileBytes;
}
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
conn.ConnectionString = _connectionString;
cmd.CommandText = "INSERT INTO REPORT_TABLE (IMAGEFIELD,IMAGENAME) VALUES (@image,@filename)";
cmd.Parameters.Add("@image", SqlDbType.Image, imageBytes.Length).Value = imageBytes;
cmd.Parameters.Add("@filename", SqlDbType.VarChar, 50).Value = uploadFileName;
cmd.Connection = conn;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Tuesday, March 17, 2009
How To do invisible a column of Gridview
In below example admin can Only view column 2 and 21.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(user != "Admin")
{
if(e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false;
}
else if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Visible=false;
e.Row.Cells[21].Visible=false
}
}
}
Monday, March 2, 2009
Page Flashing(Smooth Transform)
page will seem flashing for 0.5 second at page loading.
How To Refresh a Web Page
Write below code within '<'head>'<'/head> tag
'<'meta http-equiv="Refresh" content="10" />
Note: it will Refresh a web page every 10 seconds
Wednesday, February 25, 2009
How to find various type of co-ordinate in a Web Browser
#javascript code
Wednesday, February 18, 2009
How to open a new url in same browser window
Tuesday, February 17, 2009
How do you make Two Columns under a one Column for Excel?
Friday, February 13, 2009
Difference between dates in terms of date,month and year
Calculate day difference between two date using javascript
Thursday, February 12, 2009
How to display logo in Address bar of browser
<head runat="server">
<link rel="Shortcut icon" href="IMAGES/logo.jpg" />
<\head>
Color Name and Hexadecimal value
background color text color in black text color in white Hex Value
steelblue | steelblue | steelblue | 4682B4 |
royalblue | royalblue | royalblue | 041690 |
cornflowerblue | cornflowerblue | cornflowerblue | 6495ED |
lightsteelblue | lightsteelblue | lightsteelblue | B0C4DE |
mediumslateblue | mediumslateblue | mediumslateblue | 7B68EE |
slateblue | slateblue | slateblue | 6A5ACD |
darkslateblue | darkslateblue | darkslateblue | 483D8B |
midnightblue | midnightblue | midnightblue | 191970 |
navy | navy | navy | 000080 |
darkblue | darkblue | darkblue | 00008B |
mediumblue | mediumblue | mediumblue | 0000CD |
blue | blue | blue | 0000FF |
dodgerblue | dodgerblue | dodgerblue | 1E90FF |
deepskyblue | deepskyblue | deepskyblue | 00BFFF |
lightskyblue | lightskyblue | lightskyblue | 87CEFA |
skyblue | skyblue | skyblue | 87CEEB |
lightblue | lightblue | lightblue | ADD8E6 |
powderblue | powderblue | powderblue | B0E0E6 |
azure | azure | azure | F0FFFF |
lightcyan | lightcyan | lightcyan | E0FFFF |
paleturquoise | paleturquoise | paleturquoise | AFEEEE |
mediumturquoise | mediumturquoise | mediumturquoise | 48D1CC |
lightseagreen | lightseagreen | lightseagreen | 20B2AA |
darkcyan | darkcyan | darkcyan | 008B8B |
teal | teal | teal | 008080 |
cadetblue | cadetblue | cadetblue | 5F9EA0 |
darkturquoise | darkturquoise | darkturquoise | 00CED1 |
aqua | aqua | aqua | 00FFFF |
cyan | cyan | cyan | 00FFFF |
turquoise | turquoise | turquoise | 40E0D0 |
aquamarine | aquamarine | aquamarine | 7FFFD4 |
mediumaquamarine | mediumaquamarine | mediumaquamarine | 66CDAA |
darkseagreen | darkseagreen | darkseagreen | 8FBC8F |
mediumseagreen | mediumseagreen | mediumseagreen | 3CB371 |
seagreen | seagreen | seagreen | 2E8B57 |
darkgreen | darkgreen | darkgreen | 006400 |
green | green | green | 008000 |
forestgreen | forestgreen | forestgreen | 228B22 |
limegreen | limegreen | limegreen | 32CD32 |
lime | lime | lime | 00FF00 |
chartreuse | chartreuse | chartreuse | 7FFF00 |
lawngreen | lawngreen | lawngreen | 7CFC00 |
greenyellow | greenyellow | greenyellow | ADFF2F |
yellowgreen | yellowgreen | yellowgreen | 9ACD32 |
palegreen | palegreen | palegreen | 98FB98 |
lightgreen | lightgreen | lightgreen | 90EE90 |
springgreen | springgreen | springgreen | 00FF7F |
mediumspringgreen | mediumspringgreen | mediumspringgreen | 00FA9A |
darkolivegreen | darkolivegreen | darkolivegreen | 556B2F |
olivedrab | olivedrab | olivedrab | 6B8E23 |
olive | olive | olive | 808000 |
darkkhaki | darkkhaki | darkkhaki | BDB76B |
darkgoldenrod | darkgoldenrod | darkgoldenrod | B8860B |
goldenrod | goldenrod | goldenrod | DAA520 |
gold | gold | gold | FFD700 |
yellow | yellow | yellow | FFFF00 |
khaki | khaki | khaki | F0E68C |
palegoldenrod | palegoldenrod | palegoldenrod | EEE8AA |
blanchedalmond | blanchedalmond | blanchedalmond | FFEBCD |
moccasin | moccasin | moccasin | FFE4B5 |
wheat | wheat | wheat | F5DEB3 |
navajowhite | navajowhite | navajowhite | FFDEAD |
burlywood | burlywood | burlywood | DEB887 |
tan | tan | tan | D2B48C |
rosybrown | rosybrown | rosybrown | BC8F8F |
sienna | sienna | sienna | A0522D |
saddlebrown | saddlebrown | saddlebrown | 8B4513 |
chocolate | chocolate | chocolate | D2691E |
| | | CD853F |
sandybrown | sandybrown | sandybrown | F4A460 |
darkred | darkred | darkred | 8B0000 |
maroon | maroon | maroon | 800000 |
brown | brown | brown | A52A2A |
firebrick | firebrick | firebrick | B22222 |
indianred | indianred | indianred | CD5C5C |
lightcoral | lightcoral | lightcoral | F08080 |
salmon | salmon | salmon | FA8072 |
darksalmon | darksalmon | darksalmon | E9967A |
lightsalmon | lightsalmon | lightsalmon | FFA07A |
coral | coral | coral | FF7F50 |
tomato | tomato | tomato | FF6347 |
darkorange | darkorange | darkorange | FF8C00 |
orange | orange | orange | FFA500 |
orangered | orangered | orangered | FF4500 |
crimson | crimson | crimson | DC143C |
red | red | red | FF0000 |
deeppink | deeppink | deeppink | FF1493 |
fuchsia | fuchsia | fuchsia | FF00FF |
magenta | magenta | magenta | FF00FF |
hotpink | hotpink | hotpink | FF69B4 |
lightpink | lightpink | lightpink | FFB6C1 |
pink | pink | pink | FFC0CB |
palevioletred | palevioletred | palevioletred | DB7093 |
mediumvioletred | mediumvioletred | mediumvioletred | C71585 |
purple | purple | purple | 800080 |
darkmagenta | darkmagenta | darkmagenta | 8B008B |
mediumpurple | mediumpurple | mediumpurple | 9370DB |
blueviolet | blueviolet | blueviolet | 8A2BE2 |
indigo | indigo | indigo | 4B0082 |
darkviolet | darkviolet | darkviolet | 9400D3 |
darkorchid | darkorchid | darkorchid | 9932CC |
mediumorchid | mediumorchid | mediumorchid | BA55D3 |
orchid | orchid | orchid | DA70D6 |
violet | violet | violet | EE82EE |
plum | plum | plum | DDA0DD |
thistle | thistle | thistle | D8BFD8 |
lavender | lavender | lavender | E6E6FA |
ghostwhite | ghostwhite | ghostwhite | F8F8FF |
aliceblue | aliceblue | aliceblue | F0F8FF |
mintcream | mintcream | mintcream | F5FFFA |
honeydew | honeydew | honeydew | F0FFF0 |
lightgoldenrodyellow | lightgoldenrodyellow | lightgoldenrodyellow | FAFAD2 |
lemonchiffon | lemonchiffon | lemonchiffon | FFFACD |
cornsilk | cornsilk | cornsilk | FFF8DC |
lightyellow | lightyellow | lightyellow | FFFFE0 |
ivory | ivory | ivory | FFFFF0 |
floralwhite | floralwhite | floralwhite | FFFAF0 |
linen | linen | linen | FAF0E6 |
oldlace | oldlace | oldlace | FDF5E6 |
antiquewhite | antiquewhite | antiquewhite | FAEBD7 |
bisque | bisque | bisque | FFE4C4 |
peachpuff | peachpuff | peachpuff | FFDAB9 |
papayawhip | papayawhip | papayawhip | FFEFD5 |
beige | beige | beige | F5F5DC |
seashell | seashell | seashell | FFF5EE |
lavenderblush | lavenderblush | lavenderblush | FFF0F5 |
mistyrose | mistyrose | mistyrose | FFE4E1 |
snow | snow | snow | FFFAFA |
white | white | white | FFFFFF |
whitesmoke | whitesmoke | whitesmoke | F5F5F5 |
gainsboro | gainsboro | gainsboro | DCDCDC |
lightgrey | lightgrey | lightgrey | D3D3D3 |
silver | silver | silver | C0C0C0 |
darkgray | darkgray | darkgray | A9A9A9 |
gray | gray | gray | 808080 |
lightslategray | lightslategray | lightslategray | 778899 |
slategray | slategray | slategray | 708090 |
Dimgray | dimgray | dimgray | 696969 |
Darkslategray | darkslategray | darkslategray | 2F4F4F |
Black | black | black | 000000 |