Wednesday, 25 December 2013
Saturday, 14 September 2013
Custom Tag [with body]
1.
Create a handler file
like : myTag.java
package mypac;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
// writer: @author ashy
public class myTag extends BodyTagSupport {
/** Creates a
new instance of myTag */
public myTag() {
}
String color;
public void
setColor(String color)
{
this.color=color;
}
public int
doStartTag()throws JspException
{ try
{
JspWriter
jw=pageContext.getOut();
jw.println("<table bgcolor='"+color+"'");
jw.println("><tr><td>");
}
catch(Exception
e)
{ }
return EVAL_BODY_INCLUDE;
}
public int
doEndTag()
{
try{
JspWriter jw=pageContext.getOut();
jw.println("</td><tr/></table>");
}
catch(Exception e)
{ }
return
EVAL_PAGE;
}
}
2. Create a tag handler
under tlds folder under WEB-INF folder like:bodyTagLib.tld
Code:
<?xml version="1.0"
encoding="UTF-8"?>
<taglib version="2.0"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>bodytaglib</short-name>
<uri>/WEB-INF/tlds/bodyTagLib</uri>
<tag>
<name>ashwani</name>
<tag-class>mypac.myTag</tag-class>
<body-content>jsp</body-content>
<attribute>
<name>color</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
3. Final step is to
implement this tag like:
Code:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tlds/bodyTagLib.tld"
prefix="m"%>
<html>
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>JSP
Page</h1>
<m:ashwani
color="red">
ashwani
</m:ashwani>
</body>
</html>
Saturday, 31 August 2013
# create a multifile assembly
Þ
1.create a .cs file say <function.cs>
which stores only static function.
Þ
2.create another file inside which you placed
your main funtion say <hello.cs>(reference with namespace used if used.)
Þ
3. firstly , create a .net module: csc
/t:module function.cs
Þ
4. secondly, csc
/addmodule:function.netmodule /out:start.exe hello.cs
11:43 PM 28/08/2013
Tuesday, 20 August 2013
Display Image (path stored in database ) in gridView using Asp.net
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DisplayImages1.aspx.cs" Inherits="GrudViewImage.DisplayImages1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="image" HeaderText="image" SortExpression="image" />
<asp:ImageField DataImageUrlField="image" ControlStyle-Width="100"
ControlStyle-Height = "100" HeaderText = "Preview
Image"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:GridViewImageExampleConnectionString %>" SelectCommand="SELECT
* FROM [GridViewImage]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
Some Queries using Language integrated Query ( LINQ ).
Let Us perform some queries using Linq:
1. Retrieve all records from database
sampleDataContext sdc = new sampleDataContext();
//var data = from d
in sdc.ToyShops select d ;(retrieve all records)
var data = from d in
sdc.ToyShops select new {
id=d.toyId,name=d.toyname};// retrieve selected column
dataGridView1.DataSource = data;
2. Update records from database
sampleDataContext sdc = new sampleDataContext();
ToyShop ts =
sdc.ToyShops.Single(c => c.toyId == Convert.ToInt32(textBox1.Text));
ts.toyname = textBox2.Text;
sdc.SubmitChanges();
MessageBox.Show("records
Updated successfully !!");
3. Delete records from database
sampleDataContext sdc = new sampleDataContext();
ToyShop ts =
sdc.ToyShops.Single(c => c.toyId == Convert.ToInt32(textBox1.Text));
sdc.ToyShops.DeleteOnSubmit(ts);
sdc.SubmitChanges();
MessageBox.Show("records
deleted successfully !!");
4. Delete records from database
sampleDataContext sdc = new sampleDataContext();
ToyShop ts = new ToyShop();
ts.toyId = Convert.ToInt32(textBox1.Text);
ts.toyname = textBox2.Text;
sdc.ToyShops.InsertOnSubmit(ts);
sdc.SubmitChanges();
MessageBox.Show("data
inserted successfully ");
5. Skip() and Take()
sampleDataContext sdc = new sampleDataContext();
var data =
(from d in
sdc.ToyShops select d).Skip(1).Take(2);
dataGridView1.DataSource = data;
6. Generate Computable fields using Linq
sampleDataContext sdc = new sampleDataContext();
//var data = from d
in sdc.ToyShops select d ;(retrieve all records)
var data = from d in
sdc.ToyShops select new { id =
d.toyId, name = d.toyname,price=d.price,quantity=d.nofQuantity,netPrice=d.price*d.nofQuantity
};
dataGridView1.DataSource = data;
Note :
Where Toyshop is the name of the Table in your database .
Note :
Where Toyshop is the name of the Table in your database .
Subscribe to:
Comments (Atom)