0% found this document useful (0 votes)
90 views

Awp Practicals

The document describes creating a web application to bind data to a dropdown list control using database binding. It includes the web.config file with the database connection string. The source code shows the practical7(a).aspx page code with a dropdownlist control. Data binding to the dropdownlist is done using the visual studio options to select the data source, similar to how it was done in a previous practical example with another data control. The goal is to display database data in the dropdownlist through databinding.

Uploaded by

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

Awp Practicals

The document describes creating a web application to bind data to a dropdown list control using database binding. It includes the web.config file with the database connection string. The source code shows the practical7(a).aspx page code with a dropdownlist control. Data binding to the dropdownlist is done using the visual studio options to select the data source, similar to how it was done in a previous practical example with another data control. The goal is to display database data in the dropdownlist through databinding.

Uploaded by

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

Advanced Web Programming With C#

Practical No.6(a)

Problem Statement :- create a web application to bind data in a multiline textbox by querying in
another textbox

Database project :

Web.config :

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data
Source=’SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf ‘;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>

</configuration>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Source code :

Practical6(a).aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical6(a).aspx.cs"


Inherits="practical6_a_" %>

<!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:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"></asp:TextBox>


<br />
<br />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="106px"
style="margin-bottom: 38px" Width="165px"></asp:ListBox>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
Width="139px" />

</div>
</form>
</body>
</html>

Practical6(a).aspx.cs

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

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
using System.Data.SqlClient;
using System.Configuration;

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


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
con.Open();
SqlCommand cmd = new SqlCommand(TextBox1.Text, con);
SqlDataReader reader = cmd.ExecuteReader();
ListBox1.Items.Clear();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount - 1; i++)
{
ListBox1.Items.Add(reader[i].ToString());
}
}
reader.Close();
con.Close();
}
}

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Design…..practical6(a) :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Solution Explorer : ..1)Data.mdf 2)Practical6(a).aspx 3)Practical6(a).aspx.cs

Connection :

Right click on Data.mdf

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
and go to property…and copy connection String and paste into web.config

Create table :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Practical No.6(b)

Note : As above practical6(a) we had create one database connection and table also using this one
in further practica6(b)..and so on

Problem Statement :-Create a web application to display records by using database

Web.config:

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>

</configuration>

Source code :

practical6(b).aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical6(b).aspx.cs"


Inherits="practical6_b_" %>

<!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>
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="Label1" runat="server" Text="Student Details :"></asp:Label>


<br />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Display Records" />

</div>
</form>
</body>
</html>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
practical6(b).aspx.cs :

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 practical6_b_ : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);

SqlCommand cmd = new SqlCommand("select sid,sname from stud", con);


con.Open();
SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
Label2.Text += reader["sid"].ToString() + "" + reader["sname"].ToString() + "<br>";
}
reader.Close();
con.Close();
}
}

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Design..Pactical6(b) :

Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Practical No .6(c)

Problem Statement :- Demonstrate the use of Datalist link control.

Source code :

practical6(c).aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical6(c).aspx.cs"


Inherits="practical6_c_" %>

<!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>

</div>
<asp:DataList ID="DataList1" runat="server">
</asp:DataList>
</form>
</body>
</html>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Design..practical6(c) :

For Datalist link control we need certain steps :

Step 1:

Step 2 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 3:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 4 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 5 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 6 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 7 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 8:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Practical No.7(a)

Problem statement : Create a web application to display Databinding using DropDownlist


control

Note :In that The Databinding to DropDownList can be done using visual studio options to select
the Data Source, The step is similar as performed in practical6(c)

Web.config :

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>

</configuration>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Source code :

Practical7(a).aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical7(a).aspx.cs"


Inherits="practical7_a_" %>

<!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:DropDownList ID="DropDownList1" runat="server"


DataTextField="sname" DataValueField="sname">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [sname] FROM
[stud]">
</asp:SqlDataSource>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Click Me !" />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
practical.aspx.cs :

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;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

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


{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("select Distinct sname from stud", con);

con.Open();

SqlDataReader reader = cmd.ExecuteReader();

DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "sname";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "The name you selected is :" + DropDownList1.SelectedValue;
}
}

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Desing..practical7(a) :

Note :The output can become either two way one is through coding in .cs file

(Or we can follow certain steps as given below)

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 1:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 2:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 3:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 4 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 5 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 6:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 7 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 8:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Step 9 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Practical No.7(b)

Problem statement :- Create a web application for to display the marks of students using
database.

Web.config :

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>

</configuration>

Source code :

Practical7(b).aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practcal7(b).aspx.cs"


Inherits="practcal7_b_" %>

<!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>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
<asp:Label ID="Label1" runat="server"
Text="Select your name to get your marks :"></asp:Label>
<br />
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
//DataSourceID=”SqlDataSource1” Note:REMOVE IT
DataTextField="sname" DataValueField="smarks">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [sname], [smarks] FROM [stud]"></asp:SqlDataSource>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Get Marks" />
<br />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>

</div>
</form>
</body>
</html>

Practical7(b).aspx.cs :

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 practcal7_b_ : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string connStr =
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("select Distinct sname,smarks from stud", con);

con.Open();

SqlDataReader reader = cmd.ExecuteReader();

DropDownList1.DataSource = reader;
DropDownList1.DataTextField = "sname";
DropDownList1.DataValueField = "smarks";
DropDownList1.DataBind();
reader.Close();
con.Close();
}
}

protected void Button1_Click(object sender, EventArgs e)


{
Label2.Text = "Your Marks is :" + DropDownList1.SelectedValue;
}
}

Design…prctical7(b):

In design Take 1…Label 2..DropDownLis 3..Button 4..Label

Here is also same

1.Through coding

..OR..

Follow certain step :

Step 1 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step2:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step 3:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step4:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step 5 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step 6:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step 7:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step8:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Step 9 :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
2)

1)

Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Practical No.7(c)

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Problem Statement :- Create a web application for inserting and deleting record from a database.
(Using Execute –Non Query).

Web.config :

<?xml version="1.0"?>

<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->

<configuration>

<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>

</configuration>

Source code :

Practical7(c).aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical7(c).aspx.cs"


Inherits="practical7_c_" %>

<!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>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
<asp:Label ID="Label1" runat="server" Text="Enter student ID :"></asp:Label>
&nbsp;
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Enter student name :"></asp:Label>
&nbsp;
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Enter student marks :"></asp:Label>
&nbsp;
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Insert Record" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="delete Record" />

</div>
</form>
</body>
</html>

Practical7(c).aspx.cs :

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 practical7_c_ : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "insert into stud values(@sid,@sname,@smarks)";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
cmd.Parameters.AddWithValue("@sname", TextBox2.Text);
cmd.Parameters.AddWithValue("@smarks", TextBox3.Text);
con.Open();

cmd.ExecuteNonQuery();
Label4.Text = "Recored Inserted Successfully";
con.Close();

}
protected void Button2_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "delete from stud where sid=@sid";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@sid", TextBox1.Text);
// cmd.Parameters.AddWithValue("@sname", TextBox2.Text);
// cmd.Parameters.AddWithValue("@smarks", TextBox3.Text);

con.Open();
cmd.ExecuteNonQuery();

Label4.Text = "Recored Deleted Successfully";


con.Close();
}
}

Design..practical7(c) :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Table :

Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
When you insert record in table :

The table will be :

When you delete some records in table :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

The table will be :

Practical No.8(a)

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Problem Statement : Create a web application to demonstrate various uses and properties of
SqlDataSource

Source code :

8a.aspx.cs :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="8a.aspx.cs" Inherits="_8a" %>

<!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:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"


DataSourceID="SqlDataSource1" DataTextField="sname"
DataValueField="sname"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=DESKTOP-
E28D6T8;Initial
Catalog=AwpPractical;Integrated Security=True"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT [sname] FROM [student]"></asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate
> sid:
<asp:Label ID="sidLabel" runat="server" Text='<%# Eval("sid") %>' />
<br />
sname
:
<asp:Label ID="snameLabel" runat="server" Text='<%# Eval("sname") %>' />
<br />
smarks:
<asp:Label ID="smarksLabel" runat="server" Text='<%# Eval("smarks") %>'
/>
<br />
<br />
</
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
I mplate>
t </asp:DataList>
e <br />
m <asp:SqlDataSource ID="SqlDataSource2" runat="server"
T
e ConnectionString="Data Source=DESKTOP-
E28D6T8;Initial
Catalog=AwpPractical;Integrated Security=True"
ProviderName="System.Data.SqlClient"
SelectCommand="SELECT * FROM [student] WHERE ([sname] = @sname)" >
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="sname" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Design…..8(a)

Output:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

PracticalNo.8(b)

Problem statements :- Create a web application to demonstrate data binding using Details View
and Form View Control

Web.config :

<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>

Source code :

Practical8(b).aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical8(b).aspx.cs"


Inherits="practical8_b_" %>

<!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>

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataKeyNames="sid" DataSourceID="SqlDataSource1" Height="50px"
Width="125px">
<Fields>
<asp:BoundField DataField="sid" HeaderText="sid" ReadOnly="True"
SortExpression="sid" />
<asp:BoundField DataField="sname" HeaderText="sname"
SortExpression="sname" />
<asp:BoundField DataField="smarks" HeaderText="smarks"
SortExpression="smarks" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [stud]">
</asp:SqlDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="sid"
DataSourceID="SqlDataSource2">
<EditItemTemplate>
sid:
<asp:Label ID="sidLabel1" runat="server" Text='<%# Eval("sid") %>' />
<br />
sname:
<asp:TextBox ID="snameTextBox" runat="server" Text='<%# Bind("sname") %>' />
<br />
smarks:
<asp:TextBox ID="smarksTextBox" runat="server" Text='<%# Bind("smarks") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
sid:
<asp:TextBox ID="sidTextBox" runat="server" Text='<%# Bind("sid") %>' />
<br />
sname:
<asp:TextBox ID="snameTextBox" runat="server" Text='<%# Bind("sname") %>' />
<br />
smarks:
<asp:TextBox ID="smarksTextBox" runat="server" Text='<%# Bind("smarks") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
CommandName="Insert" Text="Insert" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
sid:
<asp:Label ID="sidLabel" runat="server" Text='<%# Eval("sid") %>' />
<br />
sname:
<asp:Label ID="snameLabel" runat="server" Text='<%# Bind("sname") %>' />
<br />
smarks:
<asp:Label ID="smarksLabel" runat="server" Text='<%# Bind("smarks") %>' />
<br />

</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [stud]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Design …practical8(b):

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

After adding the controls,configure the Data Source property of these controls in similar
manner as explained in practical 6(a)

Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Practical No.8(c)

Problem Statement :-Create a web application to display Using Disconnected Data Access and
Databinding using Gridview

Web.config :

<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<connectionStrings>
<add name="connStr" connectionString="Data Source=.\
SQLEXPRESS;AttachDbFilename=D:\sonu\TYIT\data\App_Data\Data.mdf;Integrated
Security=True;User Instance=True"></add>
</connectionStrings>
</configuration>

Source code :

Practical8(c).aspx :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="practical8(c).aspx.cs"
Inherits="practical8_c_" %>

<!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:Button ID="Button1" runat="server" onclick="Button1_Click"


style="margin-bottom: 0px" Text="Show Disconnected Fetched Data"
Width="210px" />
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="sid"
#“Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition.”
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="sid" HeaderText="sid" ReadOnly="True"
SortExpression="sid" />
<asp:BoundField DataField="sname" HeaderText="sname"
SortExpression="sname" />
<asp:BoundField DataField="smarks" HeaderText="smarks"
SortExpression="smarks" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\
Data.mdf;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [stud]">
</asp:SqlDataSource>

</div>
</form>
</body>
</html>

Practical8(c).aspx.cs :

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 practical8_c_ : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlDataAdapter objDa = new SqlDataAdapter();
DataSet objDas = new DataSet();
using (SqlConnection objConn = new SqlConnection(connStr))
{
SqlCommand objCmd = new SqlCommand("select * from stud", objConn);
objCmd.CommandType= CommandType.Text;

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
objDa.SelectCommand = objCmd;
objDa.Fill(objDas, "stud");
GridView1.DataSource = objDas.Tables[0];
GridView1.DataBind();

}
}

Design ….practical8(c):

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

           

Output :

1)

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
2)

             

          

  Practical No :9(a)

Problem statements :Create a web application to demonstrate use of GridView control


template and GridView hyperlink.

Source code :

9a.aspx

<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="9a.aspx.cs"Inherits="_9a"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
<title></title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkFieldDataTextField="sid"HeaderText="Student Id"
NavigateUrl="~/7a.aspx"/>
<asp:BoundFieldDataField="sname"HeaderText="Student Name"
SortExpression="sname"/>
<asp:BoundFieldDataField="smarks"HeaderText="Student Marks"
SortExpression="smarks"/>
</Columns>
</asp:GridView>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"
ConnectionString="<%$ConnectionStrings:ConnectString%>"
SelectCommand="SELECT * FROM [student]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>

Design….9(a)

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

Output:

Practical No.10(a)

Problem statements : Create a web application to demonstrate reading and writing operation
with XML.

Add -> new Item -> Xml file

1) abc.xml

Keep this file is empty for writing purpose

Source code :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
10(a).apsx

<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="Label"></asp:Label>


<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="xml writer" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="175px"
Width="220px"></asp:ListBox>
<br />
<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="xml reader" />
<br />

</div>
</form>
</body>
</html>

Design:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

10a.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

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


{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
XmlTextWriter writer = new XmlTextWriter("E:\\kiran more\\Ganpati

Vacation\\PRACT6\\abc", null);
writer.WriteStartDocument();

writer.WriteStartElement("names");

writer.WriteElementString("name", "kiran");
writer.WriteElementString("name", "pramod");
writer.WriteEndElement();
writer.WriteEndDocument();

writer.Close();

Label1.Text = "Data written successfully";


}

protected void Button2_Click(object sender, EventArgs e)


{
ListBox1.Items.Clear();

XmlTextReader red =new XmlTextReader("E:\\kiran more\\Ganpati


Vacation\\PRACT6\\abc");
while (red.Read())
{
if (red.NodeType == XmlNodeType.Element)
{
if (red.Name == "name")
{
Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)
Advanced Web Programming With C#
ListBox1.Items.Add(red.ReadString());
}
}

}
red.Close();

}
}

Output:

Practical no:11

Problem statements : Program to create and use dll file

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#
Source Code :

class1.cs dll:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ClassLibrary1

publicclassClass1
{

Public int addition(int a , int b)


{

int c = a + b;

return c;

program.cs:

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

using System;

usingSystem.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace dll
{
classProgram
{
Static void Main(string[] args)
{

ClassLibrary1.Class1 a = new ClassLibrary1.Class1();

int c = a.addition(5, 6);

Console.WriteLine("addition =" + c);

Console.ReadKey();

Output :

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)


Advanced Web Programming With C#

             

Sheth N.K.T.T College ,Thane T.Y.BSc.IT(2018-2019)

You might also like