0% found this document useful (0 votes)
11 views20 pages

AWDT Practical - Solution

Uploaded by

omchudasama3688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views20 pages

AWDT Practical - Solution

Uploaded by

omchudasama3688
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Program 1

protected void Page_Load(object sender, EventArgs e)


{
Label1.Text = "Hello World...!!";
Label2.Text = DateTime.Now.ToString();
}

Program 2

protected void Button1_Click(object sender, EventArgs e)


{
Label2.Text = "Hello " + TextBox1.Text+"...!!" ;
}

Program 3

protected void Button1_Click(object sender, EventArgs e)


{
TextBox3.Text = (int.Parse(TextBox1.Text) + int.Parse(TextBox2.Text)).ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox3.Text = (int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text)).ToString();
}
protected void Button3_Click(object sender, EventArgs e)
{
TextBox3.Text = (int.Parse(TextBox1.Text) * int.Parse(TextBox2.Text)).ToString();
}
protected void Button4_Click(object sender, EventArgs e)
{
TextBox3.Text = (int.Parse(TextBox1.Text) / int.Parse(TextBox2.Text)).ToString();
}

Program 4

protected void Button1_Click(object sender, EventArgs e)


{
if (RadioButton1.Checked == true)
{
if (int.Parse(TextBox1.Text) % 2 == 0)
{
TextBox2.Text = "Even";
}
else
{
TextBox2.Text = "Odd";
}
}
if(RadioButton2.Checked==true)
{
if (int.Parse(TextBox1.Text) > 0)
{
TextBox2.Text = "Positive";
}
else
{
TextBox2.Text = "Negative";
}
}

if (RadioButton3.Checked == true)
{
TextBox2.Text = (int.Parse(TextBox1.Text) * int.Parse(TextBox1.Text)).ToString();
}

if (RadioButton4.Checked == true)
{
int i,f=1;
for ( i = 1; i <= int.Parse(TextBox1.Text); i++)
{
f = f * i;
}
TextBox2.Text = f.ToString();
}
}

Program 5

protected void Button1_Click(object sender, EventArgs e)


{
if (RadioButton1.Checked == true)
{
TextBox2.Text = TextBox1.Text.ToUpper();
}

if (RadioButton2.Checked == true)
{
TextBox2.Text = TextBox1.Text.ToLower();
}

if (RadioButton3.Checked == true)
{
TextBox2.Text = TextBox1.Text.Substring(TextBox1.Text.Length-5);
}

if (RadioButton4.Checked == true)
{
TextBox2.Text = TextBox1.Text.Substring(0,5);
}
}

Program 6

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)


{
Image1.ImageUrl = "~/Images/Blue Hills.jpg";
}
protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
{
Image1.ImageUrl = "~/Images/Sunset.jpg";
}
protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
{
Image1.ImageUrl = "~/Images/Water Lilies.jpg";
}
protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
{
Image1.ImageUrl = "~/Images/Winter.jpg";
}

Program 7

protected void Button1_Click(object sender, EventArgs e)


{
if (TextBox1.Text == "1")
{
TextBox2.Text = "January";
}
else if (TextBox1.Text == "2")
{
TextBox2.Text = "February";
}
else if (TextBox1.Text == "3")
{
TextBox2.Text = "March";
}
else if (TextBox1.Text == "4")
{
TextBox2.Text = "April";
}
else if (TextBox1.Text == "5")
{
TextBox2.Text = "May";
}
else if (TextBox1.Text == "6")
{
TextBox2.Text = "June";
}
else if (TextBox1.Text == "7")
{
TextBox2.Text = "July";
}
else if (TextBox1.Text == "8")
{
TextBox2.Text = "August";
}
else if (TextBox1.Text == "9")
{
TextBox2.Text = "September";
}
else if (TextBox1.Text == "10")
{
TextBox2.Text = "October";
}
else if (TextBox1.Text == "11")
{
TextBox2.Text = "November";
}
else if (TextBox1.Text == "12")
{
TextBox2.Text = "December";
}
else
{
TextBox2.Text = "Invalid Month";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = TextBox2.Text = "";
}

Program 8

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = TextBox2.Text = TextBox3.Text = TextBox4.Text = TextBox5.Text =
TextBox6.Text = Label9.Text = Label11.Text = Label13.Text = Label15.Text = Label17.Text =
Label19.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
Label9.Text = TextBox1.Text;
Label11.Text = TextBox2.Text;
Label13.Text = TextBox3.Text;
Label15.Text = TextBox4.Text;
Label17.Text = TextBox5.Text;
Label19.Text = TextBox6.Text;
}

Program 9

protected void Button1_Click(object sender, EventArgs e)


{
Label1.Text = TextBox2.Text;
Label1.Font.Size = int.Parse(TextBox1.Text);
Label1.Font.Name = DropDownList2.SelectedValue;

if (RadioButton1.Checked == true)
{
Panel1.BorderStyle = BorderStyle.None;
}
if (RadioButton2.Checked == true)
{
Panel1.BorderStyle = BorderStyle.Double;
}
if (RadioButton3.Checked == true)
{
Panel1.BorderStyle = BorderStyle.Solid;
}

if (CheckBox1.Checked == true)
{
Image1.ImageUrl = "~/Image/Sunset.jpg";
}
else
{
Image1.ImageUrl = "";
}

if (DropDownList1.SelectedValue == "Black")
{
Panel1.BackColor = System.Drawing.Color.Black;
}
if (DropDownList1.SelectedValue == "Red")
{
Panel1.BackColor = System.Drawing.Color.Red;
}
if (DropDownList1.SelectedValue == "Yellow")
{
Panel1.BackColor = System.Drawing.Color.Yellow;
}
if (DropDownList1.SelectedValue == "Blue")
{
Panel1.BackColor = System.Drawing.Color.Blue;
}
if (DropDownList1.SelectedValue == "Green")
{
Panel1.BackColor = System.Drawing.Color.Green;
}
}

Program 10

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = TextBox10.Text = TextBox2.Text = TextBox3.Text = TextBox4.Text =
TextBox5.Text = TextBox6.Text = TextBox7.Text = TextBox8.Text = TextBox9.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox8.Text = (int.Parse(TextBox3.Text) + int.Parse(TextBox4.Text) +
int.Parse(TextBox5.Text) + int.Parse(TextBox6.Text) + int.Parse(TextBox7.Text)).ToString();

TextBox9.Text = (int.Parse(TextBox8.Text)/5).ToString();

if (int.Parse(TextBox9.Text) >= 90)


{
TextBox10.Text = "Dist";
}
else if (int.Parse(TextBox9.Text) >= 80 && int.Parse(TextBox9.Text) < 90)
{
TextBox10.Text = "First";
}
else if (int.Parse(TextBox9.Text) >= 60 && int.Parse(TextBox9.Text) < 80)
{
TextBox10.Text = "Second";
}
else if (int.Parse(TextBox9.Text) >= 33 && int.Parse(TextBox9.Text) < 60)
{
TextBox10.Text = "Pass";
}
else if (int.Parse(TextBox9.Text) < 33)
{
TextBox10.Text = "Fail";
}
}
Program 11

To set up required field validation for TextBox1 (First Name) and TextBox2 (Last
Name) using RequiredFieldValidator controls in an ASP.NET Web Forms application,
follow these steps:
Select Control to Validate:
 Set ControlToValidate to TextBox1 and TextBox2 for the respective validators.
Set Error Message:
 Use the ErrorMessage property to specify what message should appear when validation fails.
Set Error Message Color:
 Use the ForeColor property to change the color of the error message text to red.

Program 12

To set up range validation for an age input in an ASP.NET Web Forms application
using the RangeValidator control, follow these steps:

1 Select Control to Validate:


 Set ControlToValidate of RangeValidator1 to TextBox1.
2 Set Error Message:
 Use the ErrorMessage property to specify what message should appear when the
validation fails.
 Set ForeColor to Red for the error message color.
3 Configure Validation Range:
 Set MaximumValue to 30, MinimumValue to 18, and Type to Integer to define the
valid range for the age input.
Program 13

To set up password confirmation validation using the CompareValidator control in an


ASP.NET Web Forms application, follow these steps:

1 Add Controls:
 Add TextBox1 for the password and TextBox2 for the re-typed password.
 Add a CompareValidator control to compare the values of TextBox1 and TextBox2.
2 Configure CompareValidator:
 ControlToCompare: Set to TextBox1 (original password).
 ControlToValidate: Set to TextBox2 (re-typed password).
 ErrorMessage: Set to "* Both Passwords Must Be Same".
 ForeColor: Set to Red.

Program 14

To validate an email address using the RegularExpressionValidator control in an


ASP.NET Web Forms application, follow these steps:

1 Label and TextBox:


 <asp:Label ID="Label1" runat="server" Text="E-Mail ID:"></asp:Label>: Label for the email
field.
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>: Textbox for entering the email
address.
2 RegularExpressionValidator:
 ControlToValidate: Set to TextBox1, which is the TextBox you want to validate.
 ErrorMessage: Set to "* Enter a valid email address". This is the message displayed when
the input does not match the regular expression.
 ForeColor: Set to Red to make the error message appear in red.
 ValidationExpression: The regular expression pattern for validating an email address is
^[^@\s]+@[^@\s]+\.[^@\s]+$. This pattern checks for a basic structure of an email address
(e.g., [email protected]).

Program 15

To set up a custom validation for a TextBox using the CustomValidator control


in ASP.NET Web Forms, follow these steps:

1 Label and TextBox:


o <asp:Label ID="Label1" runat="server" Text="Comment:"></asp:Label>: A label for the
comment input.
o <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>: The TextBox where users
enter their comment.
2 CustomValidator:
o ControlToValidate: Set to TextBox1, which is the TextBox being validated.
o ErrorMessage: "Comment must be less than 10 characters." This is the message
displayed when the validation fails.
o ForeColor: Set to Red to make the error message appear in red.
o OnServerValidate: Points to the server-side event handler
CustomValidator1_ServerValidate that will contain the validation logic.
o Display: Set to Dynamic so the error message is shown only when validation fails.
3 Code-Behind:
CustomValidator1_ServerValidate: This method is called when the CustomValidator
performs validation.
o args.Value contains the value from TextBox1.
o args.IsValid is a boolean property that should be set to true if the validation is
successful or false if it fails.
In this case, args.IsValid is set to true if the length of the comment is less than 10
characters, otherwise false.
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs
args)
{
string inputText = TextBox1.Text.Trim();
args.IsValid = (inputText.Length <= 10);

Program 16

To configure the ValidationSummary control to display a summary of all validation


errors for the controls on your ASP.NET Web Forms page, follow these steps.

1 Add ValidationSummary Control:


 Place the ValidationSummary control on your page where you want the summary
of validation errors to appear.
2 Configure Properties:
 ForeColor: Set to Red for error messages.
 ShowSummary: Set to True to show the summary.
3 Validation Logic:
 Implement validation logic in the server-side event handlers (like
CustomValidator1_ServerValidate).
4 Clear Text property in all validation controls
Program 17

protected void Button1_Click(object sender, EventArgs e)


{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(@"D:\TY_BCA_Practicals\Practical_list\ASP.Net\Program_17\File
Upload\"+FileUpload1.FileName);
Label1.Text = "File Uploaded successfully" + FileUpload1.FileName;
}
else
{
Label2.Text="File Upload Error";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
FileUpload1.Attributes.Clear();
Label1.Text = "";
}

Program 18

protected void Button1_Click(object sender, EventArgs e)


{
Calendar1.Visible = true;
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
TextBox1.Text = Calendar1.SelectedDate.ToString("dd-MM-yyyy");
Calendar1.Visible = false;
}

Program 19
WF_19_1.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace p19
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void BtnView_Click(object sender, EventArgs e)


{
Session ["firstvale"]= ListBox1.SelectedValue.ToString();
Session["ischk"]=CheckBox1.Checked;
Server.Transfer("WebForm2.aspx");
}
}
}
WF_19_2.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace p19
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
if (Session["firstvale"] != null)
{
Label1.Text = Session["firstvale"].ToString();
}
if (Session["ischk"] != null)
{
bool isChecked = (bool)Session["ischk"];
Label2.Text = isChecked ? "Yes" : "No";
}
}
}
}
}
Program 20
XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Images/HP.jpg</ImageUrl>
<NavigateUrl>https://www.instagram.com/hardikpandya93/?hl=en</NavigateUrl>
<AlternateText>Kung Fu Pandya , Barodian</AlternateText>
<Impression>30</Impression>
<Keywords>HP king</Keywords>
</Ad>
<Ad>
<ImageUrl>~/Images/MSD.jpg</ImageUrl>
<NavigateUrl>https://www.instagram.com/mahi7781/?hl=en</NavigateUrl>
<AlternateText>Thala</AlternateText>
<Impression>30</Impression>
<Keywords>MSD</Keywords>
</Ad>
<Ad>
<ImageUrl>~/Images/VK.jpeg</ImageUrl>
<NavigateUrl>https://www.instagram.com/virat.kohli/?hl=en</NavigateUrl>
<AlternateText>King Kohli</AlternateText>
<Impression>20</Impression>
<Keywords>VK</Keywords>
</Ad>
</Advertisements>

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"
Inherits="p20.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<center><h1>Ad rotator control</h1>
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/XMLFile2.xml"
/>
</center>
</div>
</form>
</body>
</html>
Program 21
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="prg21.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.auto-style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="auto-style1">
<tr>
<td>
<asp:Image ID="Image1" runat="server" Height="200px" ImageUrl="~/Images/Virat-Kohli-18.jpeg" Width="1194px" />
</td>
</tr>
<tr>
<td>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<DynamicSelectedStyle HorizontalPadding="50px" ItemSpacing="70px" VerticalPadding="70px" />
<Items>
<asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
<asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
<asp:MenuItem Text="Services" Value="Services"></asp:MenuItem>
<asp:MenuItem Text="Products" Value="Products"></asp:MenuItem>
<asp:MenuItem Text="Contact Us" Value="Contact Us"></asp:MenuItem>
</Items>
<StaticMenuItemStyle HorizontalPadding="40px" ItemSpacing="10px" />
</asp:Menu>
</td>
</tr>
</table>
<div>

<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">


</asp:ContentPlaceHolder>
</div>
</form>
<table class="auto-style1">
<tr>
<td>&nbsp;<center>This is Footer</center></td>
</tr>
</table>
</body>
</html>
Program 22
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataBaseProg
{
public partial class Login22 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ankit
Vaghela\source\repos\DataBaseProg\App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

protected void btnSubmit_Click(object sender, EventArgs e)


{
string chk = "select count(*) from reg where (email='" + txtEmail.Text + "' and pass='" + txtPass.Text + "')";
SqlCommand com = new SqlCommand(chk, con);
con.Open();
int temp = Convert.ToInt32(com.ExecuteScalar());
if (temp == 1)
{
Response.Write("<script language=javascript>confirm('Login success')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

protected void BtnCancel_Click(object sender, EventArgs e)


{
txtEmail.Text = txtPass.Text = "";
}
}
}
Program 23
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataBaseProg
{
public partial class SignUp23 : System.Web.UI.Page
{
SqlConnection con =new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ankit
Vaghela\source\repos\DataBaseProg\App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

protected void btnReset_Click(object sender, EventArgs e)


{
txtfname.Text = txtlname.Text = txtUid.Text = txtpw.Text = txtCpw.Text = txtEmail.Text =txtBdate.Text= "";
}

protected void btnSignUp_Click(object sender, EventArgs e)


{
string ins = "INSERT INTO reg(fname,lname,uid,pass,dob,gen,email)VALUES('" + txtfname.Text + "','" + txtlname.Text + "','" +
txtUid.Text + "','" + txtCpw.Text + "','" + txtBdate.Text + "','" + rbtnGen.SelectedValue + "','" + txtEmail.Text + "')";
SqlCommand com = new SqlCommand(ins, con);
con.Open();
int rowaff = Convert.ToInt32(com.ExecuteNonQuery());

con.Close();
if (rowaff > 0)
{
Response.Write("<script language=javascript>confirm('success')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

}
}
}
Program 24
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DataBaseProg
{
public partial class CEF24 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ankit
Vaghela\source\repos\DataBaseProg\App_Data\Database1.mdf;Integrated Security=True");

protected void Page_Load(object sender, EventArgs e)


{

protected void btnsubmit_Click(object sender, EventArgs e)


{
string ins = "INSERT INTO CEF(cname,cadd,cno,city,country)VALUES('" + txtCname.Text + "','" + txtAddress.Text + "','" +
txtCno.Text + "','" + txtCity.Text + "','" + txtCountry.Text + "')";
SqlCommand com = new SqlCommand(ins, con);
con.Open();
int rowaff = Convert.ToInt32(com.ExecuteNonQuery());

con.Close();
if (rowaff > 0)
{
Response.Write("<script language=javascript>confirm('success')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

}
}

protected void btnclear_Click(object sender, EventArgs e)


{
txtCname.Text = txtAddress.Text = txtCno.Text = txtCountry.Text = txtCity.Text = "";
}
}
}
Program 25
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace DataBaseProg
{
public partial class EmpInfo25 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ankit
Vaghela\source\repos\DataBaseProg\App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{

protected void btnsave_Click(object sender, EventArgs e)


{
string ins = "insert into emp(empid,empname,dob,addr,cno,city,country)values('" + txtId.Text + "','" + txtName.Text + "','" +
txtdob.Text + "','" + txtAdd.Text + "','" + txtCno.Text + "','" + txtCity.Text + "','" + txtCountry.Text + "')";
SqlCommand com = new SqlCommand(ins, con);
con.Open();
int rowaffi = Convert.ToInt32(com.ExecuteNonQuery());

con.Close();
if (rowaffi > 0)
{
Response.Write("<script language=javascript>confirm('Inserted successfully')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

}
protected void btnUpdate_Click(object sender, EventArgs e)
{
string up = "update emp set empname='" + txtName.Text + "',dob='"+txtdob.Text+"' ,addr='"+txtAdd.Text+ "' ,
cno='"+txtCno.Text+"' ,city='"+txtCity.Text+"',country='"+txtCountry.Text+"' where empid='" + txtId.Text + "'";
SqlCommand com = new SqlCommand(up, con);
con.Open();
int rowaffu = Convert.ToInt32(com.ExecuteNonQuery());

con.Close();
if (rowaffu > 0)
{
Response.Write("<script language=javascript>confirm('Updated successfully')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

}
}

protected void btnDelete_Click(object sender, EventArgs e)


{
string del = "delete from emp where empid='" + txtId.Text + "'";
SqlCommand com = new SqlCommand(del, con);
con.Open();
int rowaffd = Convert.ToInt32(com.ExecuteNonQuery());

con.Close();
if (rowaffd > 0)
{
Response.Write("<script language=javascript>confirm('Deleted Successfully')</script>");

}
else
{
Response.Write("<script language=javascript>confirm('Something Went Wrong')</script>");

}
}

protected void btnClear_Click(object sender, EventArgs e)


{
txtId.Text=txtName.Text=txtdob.Text=txtCountry.Text=txtCno.Text=txtCity.Text=txtAdd.Text="";
}
}
}

Program 26

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Net.NetworkInformation;
using System.Web.UI.WebControls;

public partial class ClientMaster : System.Web.UI.Page


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\AnkitVaghela\source\repos\DataBaseProg\App_Data\
Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

protected void btnSave_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("INSERT INTO Clients (CNAME, CADD1, CCITY, CSTATE, CPINCODE)
VALUES (@CNAME, @CADD1, @CCITY, @CSTATE, @CPINCODE)", con);
cmd.Parameters.AddWithValue("@CNAME", txtClientName.Text);
cmd.Parameters.AddWithValue("@CADD1", txtAddress.Text);
cmd.Parameters.AddWithValue("@CCITY", txtCity.Text);
cmd.Parameters.AddWithValue("@CSTATE", txtState.Text);
cmd.Parameters.AddWithValue("@CPINCODE", txtPincode.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}

protected void btnUpdate_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("UPDATE Clients SET CNAME=@CNAME, CADD1=@CADD1,
CCITY=@CCITY, CSTATE=@CSTATE, CPINCODE=@CPINCODE WHERE CLIENTID=@CLIENTID", con);
cmd.Parameters.AddWithValue("@CLIENTID", ViewState["CLIENTID"]);
cmd.Parameters.AddWithValue("@CNAME", txtClientName.Text);
cmd.Parameters.AddWithValue("@CADD1", txtAddress.Text);
cmd.Parameters.AddWithValue("@CCITY", txtCity.Text);
cmd.Parameters.AddWithValue("@CSTATE", txtState.Text);
cmd.Parameters.AddWithValue("@CPINCODE", txtPincode.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}

protected void btnDelete_Click(object sender, EventArgs e)


{
SqlCommand cmd = new SqlCommand("DELETE FROM Clients WHERE CLIENTID=@CLIENTID", con);
cmd.Parameters.AddWithValue("@CLIENTID", ViewState["CLIENTID"]);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
BindGrid();
}

protected void btnClear_Click(object sender, EventArgs e)


{
txtClientName.Text = "";
txtAddress.Text = "";
txtCity.Text = "";
txtState.Text = "";
txtPincode.Text = "";
}

private void BindGrid()


{
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Clients", con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)


{
GridViewRow row = GridView1.SelectedRow;
ViewState["CLIENTID"] = row.Cells[1].Text;
txtClientName.Text = row.Cells[2].Text;
txtAddress.Text = row.Cells[3].Text;
txtCity.Text = row.Cells[4].Text;
txtState.Text = row.Cells[5].Text;
txtPincode.Text = row.Cells[6].Text;
}
}

Program 27
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DepartmentWiseReport : System.Web.UI.Page


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\AnkitVaghela\source\repos\DataBaseProg\
App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)


{
BindGrid();
}

private void BindGrid()


{
string department = ddlDepartment.SelectedValue;
SqlDataAdapter da;
if (string.IsNullOrEmpty(department))
{
da = new SqlDataAdapter("SELECT eno, ename, job, hiredate, sal, comm, deptname FROM
Employees", con);
}
else
{
da = new SqlDataAdapter("SELECT eno, ename, job, hiredate, sal, comm, deptname FROM
Employees WHERE deptname = @deptname", con);
da.SelectCommand.Parameters.AddWithValue("@deptname", department);
}
DataTable dt = new DataTable();
da.Fill(dt);
GridViewDept.DataSource = dt;
GridViewDept.DataBind();
}
}

Program 28

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class EmployeeInformation : System.Web.UI.Page


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\AnkitVaghela\source\repos\DataBaseProg\
App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

protected void ddlDepartment_SelectedIndexChanged(object sender, EventArgs e)


{
BindGrid();
}

private void BindGrid()


{
string department = ddlDepartment.SelectedValue;
SqlDataAdapter da;
if (string.IsNullOrEmpty(department))
{
da = new SqlDataAdapter("SELECT empno, ename, job, hiredate, sal, comm, deptname
FROM Employees", con);
}
else
{
da = new SqlDataAdapter("SELECT empno, ename, job, hiredate, sal, comm, deptname
FROM Employees WHERE deptname = @deptname", con);
da.SelectCommand.Parameters.AddWithValue("@deptname", department);
}
DataTable dt = new DataTable();
da.Fill(dt);
GridViewEmp.DataSource = dt;
GridViewEmp.DataBind();
}

protected void GridViewEmp_SelectedIndexChanged(object sender, EventArgs e)


{
GridViewRow row = GridViewEmp.SelectedRow;
lblEmpNoValue.Text = row.Cells[1].Text;
lblEmpNameValue.Text = row.Cells[2].Text;
lblJobValue.Text = row.Cells[3].Text;
lblHireDateValue.Text = row.Cells[4].Text;
lblSalaryValue.Text = row.Cells[5].Text;
lblCommValue.Text = row.Cells[6].Text;
lblDeptNameValue.Text = row.Cells[7].Text;
}
}

Program 29
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MobileDisplay : System.Web.UI.Page


{
SqlConnection con = new SqlConnection(@"Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\AnkitVaghela\source\repos\DataBaseProg\
App_Data\Database1.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}

protected void btnFindMobile_Click(object sender, EventArgs e)


{
BindGrid();
}

private void BindGrid()


{
int minAmt = string.IsNullOrEmpty(txtMinAmt.Text) ? 0 :
Convert.ToInt32(txtMinAmt.Text);
int maxAmt = string.IsNullOrEmpty(txtMaxAmt.Text) ? int.MaxValue :
Convert.ToInt32(txtMaxAmt.Text);

SqlDataAdapter da = new SqlDataAdapter("SELECT MobileId, ModelName, Price, ImageUrl


FROM Mobiles WHERE Price BETWEEN @minAmt AND @maxAmt", con);
da.SelectCommand.Parameters.AddWithValue("@minAmt", minAmt);
da.SelectCommand.Parameters.AddWithValue("@maxAmt", maxAmt);

DataTable dt = new DataTable();


da.Fill(dt);
GridViewMobile.DataSource = dt;
GridViewMobile.DataBind();
}
}

You might also like