Rushi Awp
Rushi Awp
Rushi Awp
Practical 1(a): Create an application that obtains four int value from the user and displays the
product.
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pract1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
1
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
r = Convert.ToInt32(textBox1.Text) * Convert.ToInt32(textBox2.Text) *
Convert.ToInt32(textBox3.Text) * Convert.ToInt32(textBox4.Text);
label5.Text = "Result " + r.ToString();
}
private void btnReset_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
label5.Text = "";
}
}
}
Output :
2
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pract12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
3
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
}
label5.Text = "Reverse String : " + rev.ToString();
label6.Text = "Replace 's' by 't' i String : " + s.Replace('s','t');
label7.Text = "Insert 'u' in String : " + s.Insert(3, "u");
label8.Text = "String Truncate : " + s.Trim();
label9.Text = "Remove string : " + s.Remove(4);
label10.Text = "Index of String : " + s.IndexOf('e');
}
}
}
}
4
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output :
5
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pract3
{
public partial class Form1 : Form
{
6
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
public Form1()
{
InitializeComponent();
}
7
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
}
}
8
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
case 'u':
label10.Text = "u is vowel";
break;
default:
label10.Text = "It is not vowel";
break;
}
}
}
}
Output :
9
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 1d: Create an application that receives the (Student Id, Student Name, Course Name,
Date of Birth) information from a set of students.
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace calander1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "Student ID : " + TextBox1.Text;
Label7.Text = "Student Name : " + TextBox2.Text;
Label8.Text = "Course Name : " + TextBox3.Text;
Label9.Text = "Date of Birth : " + Calendar1.SelectedDate.ToShortDateString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
10
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Label3.Text = "";
Label4.Text = "";
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Calendar1.SelectedDates.Clear();
}
}
}
Output:-
11
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 2
Practical 2(a):
(i) i) Finding factorial Value
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
class Fact
{
public int n, f;
public Fact()
{
f = 1;
}
public void cal()
{
int i;
for(i=1;i<=n;i++)
{
f = f * i;
}
}
}
namespace Practical2ai
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
12
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace conCurv
13
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public class curConv {
public double Dolr(double r)
{
r = r * 0.015;
14
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
return r;
}
public double Euros(double r)
{
r = r * 0.012;
return r;
}
public double Pound(double r)
{
r = r * 0.011;
return r;
}
public double Yen(double r)
{
r = r * 0.015;
return r;
}
}
}
15
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output:
16
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Practical2aiii
{
public partial class WebForm1 : System.Web.UI.Page
{
public void demo()
{
double a, b, c, r1, r2, x;
double det;
a = Convert.ToInt32(TextBox1.Text);
b = Convert.ToInt32(TextBox2.Text);
c = Convert.ToInt32(TextBox3.Text);
det = (b * b) - (4 * a * c);
if (det > 0)
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
r2 = (-b - x) / (2 * a);
Label1.Text = "There are two roots::";
Label2.Text = r1.ToString();
Label3.Text = r2.ToString();
}
else if (det == 0)
17
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
{
x = Math.Sqrt(det);
r1 = (-b + x) / (2 * a);
Label1.Text = "There are only one root::";
Label2.Text = r1.ToString();
}
else
{
Label1.Text = "There is no root!!";
}
}
protected void Page_Load(object sender, EventArgs e)
{
18
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace TemperatureConversion
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
19
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
{
tempConv s = new tempConv();
double n = Convert.ToDouble(TextBox1.Text);
double x = s.ctof(n);
Lbl5.Text = x.ToString();
}
}
}
public class tempConv
{
public double ctof(double temp)
{
temp = 9.0 / 5.0 * temp + 32;
return temp;
}
public double ftoc(double temp)
{
temp = (temp - 32) * 5 / 9;
return temp;
}
}
Output:
Practical 2b
(i) Function Overloading
20
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FunctionOverloading
{
public partial class WebForm1 : System.Web.UI.Page
{
public int add(int a)
{
return a + a;
}
public int add(int a, int b)
{
return a + b;
}
public int add(int a,int b,int c)
{
return a + b + c;
}
21
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
}
}
Output:
(b) Inheritance
(i) Single Inheritance
22
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Single
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
23
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
{
B s = new B();
int n = Convert.ToInt32(textBox1.Text);
int x = s.sqr(n);
int y = s.cube(n);
label4.Text = x.ToString();
label5.Text = y.ToString();
}
}
public class A
{
public int sqr(int Val1)
{
return Val1 * Val1;
}
}
public class B : A
{
public int cube(int Val1)
{
int v1 = sqr(Val1);
return v1 * Val1;
}
}
}
OUTPUT:
24
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
25
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Soruce Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Second
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
26
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
label5.Text = x.ToString();
label6.Text = y.ToString();
label7.Text = z.ToString();
}
public class A
{
public int pow2(int Val1){
return Val1* Val1;
}
}
public class B : A
{
public int pow3(int Val1){
int v1 = pow2(Val1);
OUTPUT:
27
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
28
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace hexainheritance
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
29
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
}
}
public class A
{
public int a;
public int b;
}
public class B : A
{
public int add(int Val1, int Val2)
{
a = Val1;
b = Val2;
return a + b;
}
}
public class C : A
{
public int sub(int Val1, int Val2)
{
a = Val1;
b = Val2;
return a - b;
}
}
}
30
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output:
31
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
add obj1 = new add(2);
add obj2 = new add(2,3);
add obj3 = new add(2,3,4);
Label2.Text = obj1.r.ToString();
Label3.Text = obj2.r.ToString();
Label4.Text = obj2.r.ToString();
}
}
public class add
{
public int r;
public add(int a)
{
r = a + a;
32
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
}
public add(int a, int b)
{
r = a + b;
}
public add(int a, int b, int c)
{
r = a + b + c;
}
}
}
Output:
(d) Interfaces:
33
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Rect r1 = new Rect();
double x = r1.show(3, 4);
Circle c1 = new Circle();
double y = c1.show(3, 4);
Label4.Text = x.ToString();
Label5.Text = y.ToString();
}
}
interface Area
{
double show(double s, double t);
}
34
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output:
Practical 2(c):
35
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _2cpractical
{
public partial class WebForm1 : System.Web.UI.Page
{
public delegate string dele();
public static string display1()
{
string s1 = "Yashshree Sambare";
return s1;
}
public static string display2()
{
string s2 = "Vedshree Sambare";
return s2;
}
protected void Page_Load(object sender, EventArgs e)
{
dele d1 = new dele(display1);
d1();
dele d2 = new dele(display2);
36
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
d2();
Label1.Text = d1();
Label2.Text = d2();
}
}
}
Output:
(ii)Exception handling:
37
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace practical2cii
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
38
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
{
Label3.Text = ex.ToString();
}
}
}
}
Output:
Practical 3(a)
39
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 3(a): Create a simple web Page with various server controls to demonstrate setting and
use of their properties.
WebForm1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace practi3a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str = "vinit choughule";
if (ViewState["name"]==null)
{
ViewState["name"] = str;
}
}
}
40
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Label2.Text = DropDownList1.SelectedItem.Text;
}
OUTPUT:
41
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
42
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Source Code:
Calender properties set for this example:
<asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC"
BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px"
NextPrevFormat="ShortMonth" > ShowGridLines="True" Width="300px"
>
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<NextPrevStyle BorderStyle="Solid" BorderWidth="2px" Font-Size="9pt"
ForeColor="#FFFFCC" />
<OtherMonthDayStyle BackColor="#FFCC99" BorderStyle="Solid"
ForeColor="#CC9966" />
<SelectedDayStyle BackColor="Red" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
ForeColor="#FFFFCC" />
43
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
calndrCtrl.aspx.cs
protected void btnResult_Click(object sender, EventArgs e)
{
Calendar1.Caption = "SAMBARE";
Calendar1.FirstDayOfWeek = FirstDayOfWeek.Sunday;
Calendar1.NextPrevFormat = NextPrevFormat.ShortMonth;
Calendar1.TitleFormat = TitleFormat.Month;
}
if (e.Day.Date.Day == 13 && e.Day.Date.Month == 9)
{
Calendar1.SelectedDate = new DateTime(2018, 9, 12);
Calendar1.SelectedDates.SelectRange(Calendar1.SelectedDate,
44
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Calendar1.SelectedDate.AddDays(10));
Label lbl1 = new Label();
lbl1.Text = "<br>Ganpati!";
e.Cell.Controls.Add(lbl1);
}
}
protected void btnReset_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
Label3.Text = "";
Label4.Text = "";
Label5.Text = "";
Calendar1.SelectedDates.Clear();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text = "Your Selected Date:" + Calendar1.SelectedDate.Date.ToString();
}
OUTPUT:
45
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
46
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 3(c) Demonstrate the use of Treeview control perform following operations.
a) Treeview control and datalist
b) Treeview operations
stdetail.xml
<?xml version="1.0" encoding="utf-8" ?>
<studentdetail>
<student>
<sid>1</sid>
<sname>Tushar</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>2</sid>
<sname>Sonali</sname>
<sclass>TYCS</sclass>
</student>
<student>
<sid>3</sid>
<sname>Yashashree</sname>
<sclass>TYIT</sclass>
</student>
<student>
<sid>4</sid>
<sname>Vedshree</sname>
<sclass>TYCS</sclass>
</student>
</studentdetail>
Default2.aspx
<form id="form1" runat="server">
<div>
Treeview control navigation:<asp:TreeView ID = "TreeView1" runat = "server" Width =
"150px" ImageSet="Arrows">
<HoverNodeStyle Font-Underline="True" ForeColor="#5555DD" />
<Nodes>
<asp:TreeNode Text = "ASP.NET Practs" Value = "New Node">
<asp:TreeNode Text = "Calendar Control" Value = "RED"
NavigateUrl="~/calndrCtrl.aspx">
</asp:TreeNode>
<asp:TreeNode Text = "Constructor Overloading" Value = "GREEN"
47
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
NavigateUrl="~/clsconstrc.aspx"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/singleInh.aspx" Text="Inheritance"
Value="BLUE"></asp:TreeNode>
<asp:TreeNode NavigateUrl="~/clsProp.aspx" Text="Class Properties" Value="Class
Properties"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
<NodeStyle Font-Names="Tahoma" Font-Size="10pt" ForeColor="Black"
HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle Font-Underline="True" ForeColor="#5555DD"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
<br />
Fetch Datalist Using XML data : </div>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<table class = "table" border="1">
<tr>
<td>Roll Num : <%# Eval("sid") %><br />
Name : <%# Eval("sname") %><br />
Class : <%# Eval("sclass")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
48
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Default2.aspx.cs
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
protected void BindData()
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("stdetail.xml"));
if (ds != null && ds.HasChanges())
{
DataList1.DataSource = ds;
DataList1.DataBind();
}
else
{
DataList1.DataBind();
}
}
}
OUTPUT:-
49
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical -4
Practical 4(a): Create a Registration form a demonstrated use of various Validation controls.
ValidationPract.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Practical4a.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
50
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
51
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
ForeColor="Red" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-
.]\w+)*"></asp:RegularExpressionValidator>
<br />
Custom Text:<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ClientValidationFunction="SeverValidation" ControlToValidate="TextBox6"
ErrorMessage="CustomValidator" ForeColor="Red"></asp:CustomValidator>
<asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="Validate" />
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
</div>
</form>
</body>
</html>
Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\"
/optionInfer+" />
</compilers>
52
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
</system.codedom>
</configuration>
Output
53
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical4 (b)
54
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
XML File
<Advertisements>
<Ad>
<ImageUrl>rose1.jpg</ImageUrl>
<NavigateUrl>http://www.1800flowers.com</NavigateUrl>
<AlternateText>
OUTPUT:
55
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
56
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
<!DOCTYPE html>
<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="Welcome to the World of
Vinit"></asp:Label>
</div>
<uc1:footer ID="footer1" runat="server" />
</form>
</body>
</html>
Output:
57
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 7(a): create a web application to display databinding using drop down list control.
CODE OF C# CODE BEHIND FILE
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.Web.Configuration;
namespace practical7a
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
try
{
string conStr =
WebConfigurationManager.ConnectionStrings["c1"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
SqlCommand cmd =new SqlCommand("select * from Customer",con);
SqlDataReader dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataTextField = "City";
this.DataBind();
}catch(Exception ex)
{
Label1.Text = ex.Message;
}
}
}
58
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output:
59
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Practical 8c: Create a web application to display using Disconnected Data Access and
databinding using Grid view.
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;
using System.Data;
namespace Practical8c
{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con=new SqlConnection("Data Source=LAPTOP-
NIQ8RJ1U\\SQLEXPRESS;Initial Catalog=you2;Integrated Security=True");
SqlDataAdapter da;
DataSet ds=new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from Products", con);
da.Fill(ds, "Name");
GridView1.DataSource=ds;
GridView1.DataBind();
}
}
}
60
TY-BSC-IT ADVANCE WEB PROGRAMMING 226771
Output:
61