Académique Documents
Professionnel Documents
Culture Documents
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for DataAccessLayer
/// </summary>
public class DataAccessLayer
{
string constr;
public DataAccessLayer()
{
constr =
ConfigurationManager.ConnectionStrings["dbConstr"].ToString();
}
public SqlConnection openDBCOn()
{
SqlConnection con = new SqlConnection(constr);
con.Open();
return con;
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>
<asp:ContentPlaceHolder id="title" runat="server">
</asp:ContentPlaceHolder>
</title>
<style type="text/css">
ul
{
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
background-color:#333;
}
li
{
float:left;
}
li a, .dropbtn
{
display:inline-block;
color:White;
text-align:center;
padding:14px 16px;
text-decoration:none;
}
li a:hover, .dropbtn
{
background-color:#333;
display:block;
}
li.dropdown
{
display:inline-block;
}
.dropdown-content
{
display:none;
position: absolute;
background-color: Black;
min-width:160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
dropdown-content a
{
color:Black;
padding: 12px 16px;
text-decoration: none;
display:block;
text-align:center;
}
.dropdown-content a:hover
{
background-color:Red;
}
.dropdown:hover .dropdown-content
{
display:block;
}
ul.topnav li a.active
{
background-color:#4CAF50;
}
a.active
{
background-color:#4CAF50
}
li.right
{
float:right;
background-color:Red;
}
#copyright
{
background-color:Black;
color:White;
width:100%;
height:5%;
padding:1px;
margin-top:380px;
}
</style>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul>
<li><a class="active" href="#home">Home</a></li>
<li><a href="#">Universities</a></li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Lectures</a>
<div class="dropdown-content">
<a href="#link1">Link 1</a><br />
<a href="#link2">Link 2</a><br />
<a href="#link3">Link 3</a><br />
<a href="#link4">Link 4</a><br />
</div>
</li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">Courses</a>
<div class="dropdown-content">
<a href="#link1">Link 1</a><br />
<a href="#link2">Link 2</a><br />
<a href="#link3">Link 3</a><br />
<a href="#link4">Link 4</a><br />
</div>
</li>
</ul>
<asp:ContentPlaceHolder id="body" runat="server">
</asp:ContentPlaceHolder>
<div id="copyright">
<h4>All Rights is reserved by Tech Origin @2018</h4>
</div>
</div>
</form>
</body>
</html>
VALIDATION CONTROLS:
<asp:TextBox ID="TextBox2" runat="server" type="text" name="user_name"
class="validate[required,custom[email]]" placeholder="Email Name
here..."></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Name Must be Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox3" runat="server" type="text" name="user_email"
class="validate[required]" placeholder="Enter Email Here..."></asp:TextBox><br>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ErrorMessage="Enter Valid Email Address..." ControlToValidate="TextBox3"
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
<asp:TextBox ID="TextBox4" runat="server" type="password" name="user_password"
class="validate[required]" placeholder="Enter Your password..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox4" ErrorMessage="Password Must be Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox5" runat="server" type="text" name="user_age"
class="validate[required]" placeholder="Enter Your Age..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="TextBox5" ErrorMessage="Age Entered..."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox6" runat="server" type="text" name="user_gender"
class="validate[required]" placeholder="Gender..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="TextBox6" ErrorMessage="Gender Must be Enter.."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
<asp:TextBox ID="TextBox7" runat="server" type="text" name="user_phone"
class="validate[required]" placeholder="Enter Phone Number..."></asp:TextBox><br>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="TextBox7" ErrorMessage="Contact Details Must Be Entered.."
SetFocusOnError="True"></asp:RequiredFieldValidator>
<br>
</form>
<div class="sign_in_bottom">
<asp:Button ID="Button1" runat="server" type="submit" OnClick="Button1_Click"
value="Sign Up" name="login_form" Text="Sign Up"></asp:Button ><br />
<asp:Label ID="lbmsg" runat="server" Text=""></asp:Label>
DATA INSERT WITH XML FILE:
<asp:TextBox ID="TextBox2" runat="server" type="text" name="user_name"
class="validate[required,custom[email]]" placeholder="Doctor Namer...">
</asp:TextBox><br />
//Add Button
<asp:Button ID="Button1" runat="server" type="submit"
OnClick="Button1_Click" value="Sign Up" Text="Add Doctor">
</asp:Button ><br />
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
}
}
<Doctor>
<DocName>Atif Saeed</DocName> <DocEmail>atifsaeedarts@gmail.com</DocEmail>
<DocSpeciality>Eye Specialist</DocSpeciality>
<Contact>03330333123</Contact>
<Timing>08-02</Timing>
<Address>Islamabad</Address>
</Doctor>
</DoctorList>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 292px;
}
.style2
{
width: 213px;
}
.style3
{
width: 272px;
}
.style4
{
width: 213px;
height: 36px;
}
.style5
{
width: 272px;
height: 36px;
}
.style6
{
width: 292px;
height: 36px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table height=250px>
<tr>
<td colspan=3><h1>Welcome to Email Attachment Code</h1></td>
</tr>
<tr>
<td class="style2">Email:</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server" Height="34px"
Width="208px"></asp:TextBox>
</td>
<td class="style1">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Email Must be Entered..."
SetFocusOnError="True"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td class="style4">Subject:</td>
<td class="style5">
<asp:TextBox ID="TextBox3" runat="server" Height="34px"
Width="208px"></asp:TextBox>
</td>
<td class="style6"> </td>
</tr>
<tr>
<td class="style4">Attachment:</td>
<td class="style5">
<asp:FileUpload ID="FileUpload1" runat="server" Height="22px" />
</td>
<td class="style6"></td>
</tr>
<tr>
<td class="style2">Message:</td>
<td class="style3">
<asp:TextBox ID="TextBox2" runat="server" Height="70px" TextMode="MultiLine"
Width="248px"></asp:TextBox>
</td>
<td class="style1"></td>
</tr>
<tr>
<td colspan=2>
</td>
<td class="style1">
<asp:Label ID="lbmsg" runat="server"></asp:Label>
</td>
</tr>
</table>
</form>
</body>
</html>
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("Email Here...");
msg.To.Add(TextBox1.Text);
msg.Subject = TextBox3.Text;
msg.Body = TextBox2.Text;
msg.IsBodyHtml = true;
if (FileUpload1.HasFile)
{
msg.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream,
FileUpload1.FileName));
}
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}
SEND EMAIL WITHOUT ATTACHMENT:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 410px;
}
.style2
{
width: 117px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table height=336px>
<tr>
<td class="style2">To:</td>
<td class="style1">
<asp:TextBox ID="to" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">From:</td>
<td class="style1">
<asp:TextBox ID="from" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">Subject:</td>
<td class="style1">
<asp:TextBox ID="subject" runat="server" Width="336px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">Message:</td>
<td class="style1">
<asp:TextBox ID="body" runat="server" Height="103px" TextMode="MultiLine"
Width="336px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan=2>
<asp:Button ID="send" runat="server" Text="Send" Width="122px"
onclick="send_Click" />
</td>
</tr>
<tr>
<td colspan=2>
</td>
</tr>
</table>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
}
protected void send_Click(object sender, EventArgs e)
{
try
{
MailMessage message = new MailMessage(from.Text, to.Text, subject.Text, body.Text);
message.IsBodyHtml = true;
from.Text = "";
to.Text = "";
subject.Text = "";
body.Text = "";
}
Q50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Configuration;
}
protected void btn_login_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= logon; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();
public dataaccesslayer()
{
constr = System.Configuration.ConfigurationManager.ConnectionStrings["cs"].ToString();
}
public SqlConnection opendbcon()
{
mydbcon = new SqlConnection(constr);
mydbcon.Open();
return mydbcon;
}
public DataSet fillds(string query)
{
da = new SqlDataAdapter(query, opendbcon());
ds = new DataSet();
da.Fill(ds);
return ds;
Q64
Query:
CREATE VIEW v1 AS
SELECT country
FROM kuni
WHERE srno= 1;
Design:
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
Code:
protected void Button1_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= country; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();
string q = "select * from v1 ";
SqlDataAdapter da;
da = new SqlDataAdapter(q, con);
DataSet ds;
ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
Q65
Design:
<asp:DropDownList ID="DropDownList1" runat="server"
Height="52px" Width="249px" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
code:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dataaccesslayer obj = new dataaccesslayer();
obj.FillDD(DropDownList1, "select * from tblDepartment");
}
}
Q66
USE [country]
GO
/****** Object: StoredProcedure [dbo].[pro] Script Date: 02/07/2019 15:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[pro]
(
@srno int,
@country varchar(50),
@StatementType nvarchar(20) = ''
)
AS
BEGIN
IF @StatementType = 'Insert'
BEGIN
insert into kuni (country) values( @country)
END
IF @StatementType = 'Select'
BEGIN
select * from kuni
END
IF @StatementType = 'Update'
BEGIN
UPDATE kuni SET
country = @country
WHERE srno = @srno
END
else IF @StatementType = 'Delete'
BEGIN
DELETE FROM kuni WHERE srno = @srno
END
end
Q69
Q75
webservice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
[WebMethod]
public int add(int x, int y)
{
int z;
z = x + y;
return z;
}
}
Design:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
code:
design:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
code:
protected void Button1_Click(object sender, EventArgs e)
{
string con = @"Data Source = (local); Initial Catalog= country; Integrated Security= true;";
SqlConnection myDB = new SqlConnection(con);
myDB.Open();
Q80
xml:
<srno>
2
</srno>
<room>
cl2
</room>
<srno>
2
</srno>
<room>
cl3
</room>
</class>
design:
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
code:
using previous class webconfig...
ds = new DataSet();
ds.ReadXml(Server.MapPath("XMLFile.xml"));
GridView1.DataSource = ds.Tables[1];
GridView1.DataBind();
}
}