Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Application["c"].ToString();
}
}
After You write this code and next You Build thet website. Build
website Press F6 Button.
When website is builded then close Your website and create new
website name any you give.
In new website “Default.aspx” page in take One Textbox and One
Button. And write code in Button click
Before or after take control first add your StudentClassLibrary
website in Your website.
Adding StudentClassLibrary in Your website Open Solution
Explorer in Solution Explorer Select This
And rightclick there and select
“AddReferance” then Opened one popup window and there find
your StudentClassLibrary website and go in to
CODE :-
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 5; i++)
{
TextBox2.Text += "Gujarat Uni\n";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
student s = new student();
int v = Convert.ToInt32(TextBox1.Text);
int x = s.fect(v);
Label1.Text = x.ToString();
}
}
( 3 ) Program : 3
Default.aspx
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click1(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(txtA.Text);
b = Convert.ToInt32(txtB.Text);
c = sum(a, b);
txtAdd.Text = c.ToString();
}
public int sum(int x, int y)
{
return x + y;
}
public int mul(int x, int y)
{
return x * y;
}
protected void btnmul_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(txtA.Text);
b = Convert.ToInt32(txtB.Text);
c = mul(a,b);
txtMul.Text = c.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
: Write a program to take two link button and panel click one linkButton and
show one panel and click another link button to show another panel
: Write a program to add item in lable when you check checkbox with use of
checkboxlist control.
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = false;
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Panel2.Visible = true;
Panel1.Visible = false;
Label2.Text=((Convert.ToInt32(Txtcontity.Text))*(Convert.ToInt32(Label1.Text
))).ToString();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender,
EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
bodyid.Attributes.Add("bgcolor","red");
}
else if (RadioButtonList1.SelectedIndex == 1)
{
bodyid.Attributes.Add("bgcolor","green");
}
else if (RadioButtonList1.SelectedIndex == 2)
{
bodyid.Attributes.Add("bgcolor", "blue");
}
else if (RadioButtonList1.SelectedIndex == 3)
{
bodyid.Attributes.Add("bgcolor", "yellow");
Unit 2 ( 9 ) :
( 5 ) Program 5:
XMLFile.xml
Unit 2 ( 8 ) :
( 6 )Program 6 :
IMAGE MEP.
COOKIS....
Default2.aspx
CODE :
public partial class cookis_page : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookies = Request.Cookies["c"];
if (cookies != null)
{
TextBox1.Text = cookies["no"].ToString();
TextBox2.Text = cookies["name"].ToString();
TextBox3.Text = cookies["price"].ToString();
TextBox4.Text = cookies["qty"].ToString();
}
}
}
Unit 2 ( 7 ) :
( 8 )Program 8:
Default.aspx
//USING SESSION
/*
Session["username"] = TextBox1.Text;
Response.Redirect("Default2.aspx");
*/
}
}
if (Request.Cookies["username"] != null)
{
Response.Write(Request.Cookies["username"].Value.ToString());
}
//USING SESSION.
( 9 ) Program 9 : (UNIT 2 : 1)
Default.aspx
Unit 2 ( 5 ) :
( 10 )Program 10: ( UNIT : 2_5)
: Write a program to select on city select in dropdown list and show states in
another dropdown list.
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
DropDownList2.Items.Clear();
if (DropDownList1.SelectedIndex == 1)
{
DropDownList2.Items.Add("abc");
DropDownList2.Items.Add("def");
DropDownList2.Items.Add("ghi");
}
else if (DropDownList1.SelectedIndex == 2)
{
DropDownList2.Items.Add("jkl");
DropDownList2.Items.Add("mno");
DropDownList2.Items.Add("pqr");
}
else if (DropDownList1.SelectedIndex == 3)
{
DropDownList2.Items.Add("stu");
DropDownList2.Items.Add("vwx");
DropDownList2.Items.Add("yz");
}
}
}
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileExt =
System.IO.Path.GetExtension(FileUpload1.FileName);
int len = FileUpload1.PostedFile.ContentLength;
if (len > 10000)
{
Label2.Text = "Image is More then 10KS";
return;
}
( 12 )Program 12 :
{ CLASSLIBRARY }
First Create New project and celect Class library.
In class library change class name in soluation Explorer. select class.cs
and press F2 function key and change class name. Not Change directly.
And write code in a class.cs
Remeber where Your classlibrary was saved ?
CODE :
namespace ClassLibrary2
{
public class student
{
int x = 1;
public int fact(int m)
{
for (int i = 1; i <= m; i++)
{
x = x * i;
}
return (x);
CODE :
{
protected void Page_Load(object sender, EventArgs e)
{
student s = new student();
int x=s.fact(5);
TextBox1.Text = x.ToString();
}
}
( 13 )Program 13:
{ DATABASE }
Unit 4 ( 8 ) :
1. Insert, update, Delete.
First create database in Access.
Create table student and fild is id1,name1,dob1.
Where dob fild change Formate = Short Date. And input Mask =
99/99/9999.
Write Code :
CODE :
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\std.mdb");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand("insert into student
values('"+TextBox1.Text+"','"+TextBox2.Text+"',#"+TextBox3.Text+"#)",con);
cmd.ExecuteNonQuery();
Label4.Text = "data saved successfully...";
cmd.Dispose();
Unit 3 ( 2 ) :
2. LOGIN FORM WITH FORGET PASSOWRD.
First Create Database In Access.
And create table login and fild is uname1,password1,email1,user1.
And insert two any data one admin and second local user.
Opeon visual studio and add database in surver explorer.
Write code in button Click event (Default.aspx).
CODE :-
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\login.mdb");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
OleDbDataReader red;
OleDbCommand cmd = new OleDbCommand("select * from login1 where
uname1='" + TextBox1.Text + "' and password1='" + TextBox2.Text + "'", con);
red = cmd.ExecuteReader();
if (red.Read() == true)
{
Label4.Text = "Authorised User..";
Label5.Text = red["user1"].ToString();
cmd.Dispose();
TextBox1.Text = "";
TextBox1.Focus();
}
else
{
Label4.Text = "Invalid user username or password";
Label5.Text = "";
TextBox2.Text = "";
TextBox2.Focus();
}
}
catch (Exception e1)
{
Label5.Text = e1.Message;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
CODE :
public partial class Default2 : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\login.mdb");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
TextBox1.Focus();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
OleDbDataReader red;
OleDbCommand cmd = new OleDbCommand("select * from login1 where
uname1='"+TextBox1.Text+"'",con);
red = cmd.ExecuteReader();
CODE :
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\doctor_pateton.mdb");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
if(DropDownList1.SelectedIndex==1)
{
try
{
OleDbCommand cmd = new OleDbCommand("select * from
doc",con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt=new DataTable();
da.Fill(dt);
Unit 2 ( 10 ) :
4. Select Date From Calender Control And press Button then
Show Name Of person how Was Born in selected Date Othervise
give message.
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
try
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\birthdate.mdb");
OleDbCommand cmd = new OleDbCommand("select * from student where
bdate=#"+TextBox1.Text+"#",con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
Unit 4 ( 6 ) :
CODE :
Unit 2 ( 3 ) :
6.Write a program to show your database table data on
repiter for button click.
CODE :
Unit 4 ( 9 ) :
CODE :
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\unit4_9.mdb");
protected void Button1_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand("insert into emp
values('"+TextBox1.Text+"','"+TextBox2.Text+"','"+DropDownList1.SelectedValu
e+"','"+DropDownList2.SelectedValue+"')",con);
cmd.ExecuteNonQuery();
Label5.Text = "Data Saved Successfully...";
demo1();
TextBox2.Text = "";
TextBox2.Focus();
}
public void demo1()
{
int x=0;
OleDbCommand cmd = new OleDbCommand("Select *from emp",con);
OleDbDataReader red;
red = cmd.ExecuteReader();
CODE :
public partial class _Default : System.Web.UI.Page
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Users\\DELL\\Desktop\\Mayank\\COLLAGE\\C
Sharp\\Database\\unit4(10).mdb");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
OleDbCommand cmd = new OleDbCommand("select c.name1 as Customer,
p.pcode As Product_Number,p.name1 As Product_Name, (p.price1*p.qty1) As
Total from pro p,cus c where c.ccode=p.pcode", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
CODE :
public partial class _Default : System.Web.UI.Page
{
protected void LinkButton1_Click(object sender, EventArgs e)
{
HttpCookie c = new HttpCookie("product");
c["pname"] = LinkButton1.Text;
Response.Cookies.Add(c);
Response.Redirect("Default2.aspx");
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
HttpCookie c = new HttpCookie("product");
c["pname"] = LinkButton2.Text;
Response.Cookies.Add(c);
Response.Redirect("Default2.aspx");
}
}
CODE :
Unit 4 ( 5 ) :
5[Unit:-4(5)] : Write a program to create new website and
in a website user upload image in a database with use of
fileUpload control. And user is also show individual image
with use image no. When user add image no and click display
button and show image in image control.when user upload new
image in database gridview was atomomaticaly updated and
show data in a gridview.
CODE :
Unit 4( program 7 )
First Create New website in web site add two form
1) Register.aspx page
2) Login.aspx page
Second Opeon Microsoft Access and create one database
and create one table reg.
Database :-
1) Register.aspx page
In Register.aspx page take 6 TextBox and 8 Label and 1
Button (Register).
Write code on Button Click.
Code :-
using System.Data.OleDb;
2) Login.aspx page..
In Register.aspx page take 3 TextBox, 6 Label, 1 Button
(Login) and 1 Gridview.
Write code on Button click..
Code :
First add Header file..
using System.Data.OleDb;
using System.Data;(if You Use Visual Studio 2012, For DataTable Hint).
MasterPage
First Create New Empity website.
Next open add new item popup box and select “Master page”.
And press add.
In master page write HTML code in sorce code.
In website add 4 .aspx pages.and give link in html code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" />
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div class="wrapper">
<div class="manu">
<ul>
<li><a href="Default.aspx">Home</a></li>
<li><a href="Default2.aspx">Category</a></li>
<li><a href="Default3.aspx">Contect</a></li>
<li><a href="Default4.aspx">About</a></li>
</ul>
</div>
<div class="contect">
<asp:ContentPlaceHolder id="contentbody" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="clear"></div>
<div class="footer">
<h2>Mayank Solanki</h2>
</div>
</div>
</form>
</body>
</html>
When you add 4 .aspx page first checked “Select master page”
And also check “place code in separated” checkboxes in add
new item window...
Code :
body,div,p,ui,li
{
padding:0;
margin:0;
}
body {
background-color:rgb(237,237,237);
font-family:"Arial",sans-serif;
font-size:12px;
}
.wrapper {
width:1000px;
margin:auto;
}
.contect {
width:100%;
background-color:rgb(254,254,254);
border:1px solid rgb(224,224,224);
float:left;