Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Awp (7a & 7B)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Practical No.

: - 7
A) Create a web application bind data in a multiline textbox by querying in another
textbox.
How to create database?
Open Database Explorer → Right Click on Data Connection → Select option ‘Add Connection’
→ In new Window, Select option Microsoft SQL Server Database File and Click on OK button
→ In New Window, Put New Database Name (TYIT) → Click on OK Button. → Click on Yes
Button.
How to create table?
After creating Database, expand your database (tyit.mdf). It will shows different folders. In that
find Tables folder and right click on that folder → select Add New Table option → from
Property tab change the table name from Table1 to sem5 and provide following column name.

Then Save the all columns name. When you expand the Tables folder, it will shows your sem5
table. Also expand sem5 table, it will shows your all columns name which you created. Then
right click on sem5 Table and select Show Table Data option. Enter following data:

After that go to solution explorer and add New Page (Default.aspx)


Code:
Default.aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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> </head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Enter Query: " Font-Size="XX-
Large"> </asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="TextBox1" runat="server" Font-Size="X-Large"
Width="400px">
</asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Font-Size="X-Large"
onclick="Button1_Click" Text="Execute query" />
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server" Font-Size="X-Large"
Height="300px"
TextMode="MultiLine" Width="400px"></asp:TextBox>
</div>
</form>
</body>
</html>

Default.aspx.cs Page:
using System;
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.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
string constr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\ANKITA
SHINDE\Documents\tyit.mdf;Integrated Security=True;Connect Timeout=30;User
Instance=True";
SqlConnection con = new SqlConnection(constr);
con.Open();SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
SqlDataReader reader = cmd.ExecuteReader();
TextBox2.Text = "";
while (reader.Read())
{
TextBox2.Text += Environment.NewLine;
for (int i = 0; i < reader.FieldCount;i++)
{
TextBox2.Text += reader[i].ToString() + "\t";
}
}
reader.Close();
con.Close();
}
}

Output:
B)External CSS
Code:
Default.aspx Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs"
Inherits="Default3" %>
<!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>
<link rel="Stylesheet" type="text/css" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:Label ID="Label1" runat="server" Text="Practical No. 8" Font-Size="XX-
Large"></asp:Label>
<hr />
<h1>This is External CSS Example.</h1>
<br />
<h2>B. N. Bandodkar College of of Science, Thane.</h2>
</div>
</form>
</body>
</html>

Go to Solution Explorer → Right Click on Website Project → select Add New


Item option → select StyleSheet Template → Add Following Code.
StyleSheet.css Page:
body{
background-color:Aqua;
}
h1{
background-color:Maroon;
font-family:Monotype Corsiva;
font-style:italic;
color:White;
}
h2{
font-family: Century Schoolbook;
color: red;
text-decoration: underline;
}

Output:

You might also like