Lab Exercises and Solutions
Lab Exercises and Solutions
Excercise 1
The different options for the list box must be ASP-XML, DotNET, JavaPro and Unix,C,C++. When the
Submit Form button is clicked after entering the data, a message as seen in the last line of the above
figure must be displayed.
Excercise 2
Write a program to display three images in a line. When any one of the images is clicked, it must be
displayed below. On clicking the displayed image it must be cleared. The screen must look as in the
figure given below:
Lab 2
Excercise 1
Write a simple ASP.NET program to display the following Web Controls:
• A button with text “click me”. The button control must be in the center of the form.
Excercise 2
Write a program to display “Welcome To Radiant” in the form when the “click” button is clicked. The
form title must be ASP.NET.
Excercise 3
Write a program that displays a button in green color and it should change into yellow when the mouse
moves over it.
Lab 3
Excercise 1
Write a program containing the following controls:
• A ListBox
• A Button
• An Image
• A Label
The listbox is used to list items available in a store. When the user clicks on an item in the listbox, its
image is displayed in the image control. When the user clicks the button, the cost of the selected item is
displayed in the control.
Excercise 2
Excercise 3
Excercise 4
Write a JavaScript code that displays two advertisements alternately. When the user clicks on one of
the advertisements, he/she is redirected to “www.amazon.com”, and the other advertisement
redirects the user to “www.fabmart.com”. The weightage of the amazon advertisement is 50 and that
of the other one is 40. The advertisement should be centered horizontally and should cover 60% of the
width of the screen. Its height should be 80 units. The width of the border should be 5 units.
Lab 4
Excercise 1
Write a program to get a user input such as the boiling point of water and test it to the appropriate
value using CompareValidator.
Excercise 2
Write a program that uses a textbox for a user input name and validate it for RequiredField Validation.
Excercise 3
Write a prgoram that gets user input such as the user name, mode of payment, appropriate credit card.
After the user enters the appropriate values the Validation button validates the values entered.
Lab 5
Excercise 1
Create a Form that receives the user name, address, date, nationality, country preferred for working and
skill sets from the user and stores the user name in the client using cookies. The country preferred data
should appear in a dropdownlist whereas, others should be entered in a textbox. Validate all the
controls. The Form is named “formexp.aspx”. The date should appear between “1/1/1900” and
“1/1/2090”.
Lab 6
Excercise 1
Create an application that illustrates how a content can be buffered.
Lab 7
Excercise 1
Create a Global.asax file with Application variables cont, color1 and gotohp. Create a Session variable
called cont1. Initialize cont as 0 and assign any color to color1. For the variable gotohp, give a hyperlink
to any Website. Use the variables in a Web Form. Try these with the lock and unlock methods.
Lab 8
Excercise 1
1. Create table CANDIDATE with the following columns and datatypes
3. Change the candidate name from ‘S.Raman’ to ‘R.Krishnan’ in the first record in CANDIDATE
table.
4. Drop the table CANDIDATE.
5. Create table Employee with the following columns and datatypes.
Dept Numeric
Name Varchar(20)
Doj Datetime
Sal Float
Desgin Varchar(20)
11. Select the employee name, which has ‘o’ as 2 and 3 letter.
12. Update the salary of employees by 1000 for those drawing less than 2000.
13. Find out the average salaries of employees department wise.
14. Create a table “students” with the below given column.
COLUMN DATATYPE
Scode number(6)
Sname char(30)
Marks number(3)
Lab 9
Excercise 1
Write a program to connect to the master database in SQL Server, in the Page_Load event. When the
connection is established, the message “Connection has been established” should be displayed in a label
in the form.
Excercise 2
Write a program to create a table emp in the master database with the following fields:
Excercise 3
Write a program that updates the ename field of the emp table with the given name, where eno=102.
Excercise 4
Write a program to select those rows from the emp table whose eno >=100.
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
5
ASP.NET
Lab 10
Excercise 1
Select the names of the employees from the emps table. Retrieve the result in a DataSet and display it
in a CheckBoxList.
Excercise 2
Select names from the emps table. Retrieve the result in a DataSet. Bind the DataSet to a
RadioButtonList and display the result in three diferent forms as follows:
i) The RepeatDirection property of the RadioButtonList is set to horizontal and its RepeatLayout
property is set to Table.
ii) The RepeatDirection property of the RadioButtonList is set to Vertical and its RepeatLayout
property is set to Table.
iii) The RepeatLayout property of the RadioButtonList is set to flow.
Excercise 3
Create a Table, which displays two columns and three rows. The first row displays eno, the second
displays ename and the third displays esal, all of these being retrieved from the emps table. Each of the
above is displayed as a drop-down list, containing all the values of the corresponding column in the
table.
Lab 11
Excercise 1
Write a program that binds the properties ID, Name, Price and Qty of a page to the following values:
ID: 10
Name: Wheat
Price: 14.25
Qty: 1000
Excercise 2
Create a RadioButtonList that displays the names of some flowers in two columns. Bind a label to the
RadioButtonList so that when the user selects an option from the list and clicks on a button, the label
displays the flower selected by the user.
Excercise 3
Bind a CheckBoxList to the pname field of the product table in the master database so that all the name
of the product are displayed as a series of checkboxes.
Lab 12
Excercise 1
Write a program to display the records from the database as shown in the figure:
Note: Create a table Customer with records shown in the above figure.
Excercise 2
Write a program to implement the sorting feature in the customer table as shown in the figure:
Note: Create a table Customer with records shown in the above figure.
Excercise 3
Write a program to implement paging feature in the customer table as shown in the figure below.
Note: Create a table Customer with records shown in the above figure.
Lab 13
Excercise 1
• ASP.NET
• ADO.NET
• C#
It also contains a textbox in which the user has to enter a name and a textarea in which the user has to
enter his comments. When the Submit is clicked, the output should display the name entered in the
textbox and the user-selection from the listbox. All the above should be displayed with the tracing for
the page being enabled.
Excercise 2
Write a Web application that generates the “IndexOutOfRange” exception when a button is clicked.
Instead of displaying the above exception, it redirects the user to a custom error page. All the above
should be done with the trace for the page being enabled.
Excercise 3
Write a Web application that retrieves the names of the employees from the emp table. The trace for the
page should be enabled.
Lab 14
Excercise 1
Create a user control that contains a list of colors. Add a button to the Web Form which when clicked
changes the color of the Form to the color selected from the list.
Excercise 2
Create a user control that displays the current date and time. Include it in a Web Form and refresh it
each time a button is clicked.
Excercise 3
Create a user control that receives the user name and password from the user and validates them. If the
user name is “Radiant” and the password is “asp.net” then the user is authorized, otherwise not.
Lab 15
Excercise 1
Create a component that receives two numbers from the user through a Web Form, and based on the
user’s selection it adds or subtracts the two numbers and returns the result to the Web Form. The
result should be displayed in the Web Form.
Excercise 2
Create two components, the first of which is an abstract class containing an abstract method. The second
component should implement the first component’s abstract class and returns a string from the method.
Display the result in a Web Form.
Excercise 3
Create a component that contains an array of 100 integers and a corresponding indexer. From a Web
page, assign values to some of its elements. Then the Web Form should display the first 10 elements of
the indexer.
YZ
Exercise : 1
<html>
<head>
<title>Radiant Software Limited - Feedback Form</title>
<script language=”C#” runat=”server”>
void Button1_Click(object Source, EventArgs e)
{
String str = “”;
if (Male.Checked == true)
str=”Mr.”;
else if (Female.Checked == true)
str=”Miss.”;
<body>
<h5><font face=”Arial”>Courseware Feedback Form</font></h5>
<form runat=server>
<p>Student name:<input id=”name” type=text size=40 runat=”server”><br>
<p>Technical Coverage:</p>
<input type=”radio” id=”Excellent” name=”Mode2"
runat=”server”/>Excellent<br>
<input type=”radio” id=”Good” name=”Mode2" runat=”server”/>Good<br>
<input type=”radio” id=”Average” name=”Mode2" runat=”server”/>Average<br>
<input type=”radio” id=”Poor” name=”Mode2" runat=”server”/>Poor
<p>Suggestions:</p>
<textarea id=”TextArea1" runat=”server” cols=40 rows=2 />
<input type=button id=”Button1" value=”Submit Form”
OnServerClick=”Button1_Click” runat=”server”>
<p><span id=”Message” runat=”server”/>
</form>
</body>
</html>
Exercise : 2
<head>
<script language=”C#” runat=”server”>
</script>
</head>
<form runat=”server”>
<p>Click on any of the first three images to display it at the bottom
<p>Click on the bottom image to clear it</p>
<p><input type=image id=”Image1" src=”d:/images/circle.bmp”
OnServerClick=”Button1_Click” runat=”server”>
<input type=image id=”Image2" src=”d:/images/square.bmp”
OnServerClick=”Button2_Click” runat=”server”>
<input type=image id=”Image3" src=”d:/images/triangle.bmp”
OnServerClick=”Button3_Click” runat=”server”> </p>
<hr>
<input type=image id=”Image4" src=”” OnServerClick=”Button4_Click”
runat=”server”>
</form>
Lab – 2
Exercise : 1
<html>
<head>
<title> Web Controls </title>
<center>
<asp:button id=”b1" text=”Click me” runat=”server” />
</asp:button>
</center>
<asp:label id=”L1" text=”Hello” runat=”server” />
</asp:label>
<asp:checkbox id=”C1" runat=server/>
</asp:checkbox>
</head>
</html>
Exercise : 2
<html>
<head>
<title> ASP.NET </title>
<script language=”c#” runat=”server”>
void button1_Click(Object Sender,EventArgs E)
{
s1.InnerHtml=”Welcome To Radiant”;
}
</script>
</head>
<center>
<asp:button id=”b1" OnClick=”button1_Click” text=”Click me” runat=”server”
/>
</asp:button>
</center>
<span id=s1 runat=”server” />
</form>
</body>
</html>
Exercise : 3
<html>
<head>
<title> ASP.NET </title>
</head>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
13
ASP.NET
</form>
</body>
</html>
Lab – 3
Exercise : 1
<html>
<head>
<Script language=”c#” runat=”Server”>
Cost.Text += “30”;
else if (i==1)
Cost.Text += “32”;
else if (i == 2)
Cost.Text += “28”;
else
Cost.Text += “26”;
}
}
void display(Object sender, EventArgs e)
{
int i = Store.SelectedIndex;
if (i==0)
{
Img.ImageUrl = “Cola.gif”;
Img.AlternateText = “Cola”;
}
else if (i==1)
{
Img.ImageUrl = “Red_pop.gif”;
Img.AlternateText = “Red Pop”;
}
else if (i == 2)
{
Img.ImageUrl = “Lime.gif”;
Img.AlternateText = “Lime”;
}
else
{
Img.ImageUrl = “Purple_Rain.gif”;
Img.AlternateText = “Purple Rain”;
}
}
</Script>
</head>
<body>
<form runat=”server”>
<asp:label id = “label1” Text=”Choose one of the items below”
Font-Name=”Verdana” Font-Size=”18pt” runat=”server” />
<br><br>
<asp:listbox id=”Store” AutoPostBack=”True” width=”200"
runat=”server” onSelectedIndexChanged=”display”>
<asp:listitem>Cola</asp:listitem>
<asp:listitem>Red Pop</asp:listitem>
<asp:listitem>Lime</asp:listitem>
<asp:listitem>Purple Rain</asp:listitem>
</asp:listbox>
<asp:Image ID=”Img” ImageUrl=”” AlternateText=”” runat=”server” />
<br><br>
<asp:button id=”Find” text=”Find Cost” OnClick=”Calculate”
runat=”server”/>
<br><br>
<asp:textbox id=”Cost” text=”0" width=350 runat=”server”/>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
15
ASP.NET
</form>
</body>
</html>
Exercise : 2
<html>
<head>
<Script language=”c#” runat=”Server”>
void Calculate(Object sender,EventArgs e)
{
if (Store.SelectedIndex > -1){
int i = Store.SelectedIndex;
Cost.Text = “You have chosen “ + Store.SelectedItem.Value + “ and
its cost is Rs.”;
if (i==0)
Cost.Text += “30”;
else if (i==1)
Cost.Text += “32”;
else if (i == 2)
Cost.Text += “28”;
else
Cost.Text += “26”;
}
}
void display(Object sender, EventArgs e)
{
int i = Store.SelectedIndex;
if (i==0)
{
Img.ImageUrl = “Cola.gif”;
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
16
Lab Solutions
Img.AlternateText = “Cola”;
}
else if (i==1)
{
Img.ImageUrl = “Red_pop.gif”;
Img.AlternateText = “Red Pop”;
}
else if (i == 2)
{
Img.ImageUrl = “Lime.gif”;
Img.AlternateText = “Lime”;
}
else
{
Img.ImageUrl = “Purple_Rain.gif”;
Img.AlternateText = “Purple Rain”;
}
}
void add(Object sender, EventArgs e)
{
int tot=0;
int qty = System.Int32.Parse(qtyText.Text);
switch(Store.SelectedIndex)
{
case 0: tot = qty * 30;
break;
case 1: tot = qty * 32;
break;
case 2: tot = qty * 28;
break;
case 3: tot = qty * 26;
break;
}
total.Text = “You have to pay a total of Rs.” + tot;
}
</Script>
</head>
<body>
<form runat=”server”>
<asp:label id = “label1” Text=”Following are the items available with us”
Font-Name=”Verdana” Font-Size=”18pt”
runat=”server” />
<br><br>
<asp:listbox id=”Store” AutoPostBack=”True” width=”200" runat=”server”
onSelectedIndexChanged=”display”>
<asp:listitem>Cola</asp:listitem>
<asp:listitem>Red Pop</asp:listitem>
<asp:listitem>Lime</asp:listitem>
<asp:listitem>Purple Rain</asp:listitem>
</asp:listbox>
Exercise : 3
TitleStyle-BackColor=”green”
TitleStyle-ForeColor=”white”
TitleStyle-Font-Bold=”True”
/>
</form>
Exercise : 4
The ASPX file:
<html>
<body>
<Center>
<asp:AdRotator Width = “60%” Height=80 id=a1
AdvertisementFile=”ads.xml” BorderWidth=5 runat=server />
</Center>
</body>
</html>
</Ad>
</Advertisements>
Lab – 4
Exercise : 1
<html>
<body>
<form runat=”server”>
<asp:label id=”label” text=”Enter the Boiling point of water : “
runat=”server” />
<asp:textbox id=”text1" text=” “ runat=”server”/>
<asp:comparevalidator id=”compboilpt” controltovalidate=”text1"
Type=”Integer”
ValueToCompare=100 Operator=”Equal” display=”static” errormessage=”Please
enter correct value” runat=”server”>
</asp:comparevalidator>
<asp:ValidationSummary id=”sumErrors” runat=”server”
showSummary = true
displayMode = “BulletList” />
<br>
<asp:button id=bt1 runat=”server” text=”click”/>
</form>
</body>
</html>
Exercise : 2
<html>
<body>
<h3>RequiredFieldValidation</h3>
<form runat=server>
Name: <asp:Textbox id=”txtName” runat=”server”></asp:Textbox>
<asp:button id=”Button1" runat=”server” text=”Validate” />
<p>
<asp:RequiredFieldValidator id=”RequiredFieldValidator1" runat=”server”
ControlToValidate=”txtName”
ErrorMessage=”Name is a required field”
ForeColor=”Red”>
</asp:RequiredFieldValidator>
</form>
</body>
</html>
Exercise : 3
<html>
<script language=”c#” runat=”server”>
void btnclick(Object Sender,EventArgs E)
{
if (Page.IsValid ==true)
{
label1.Text=”Valid”;
}
}
</script>
<body bgcolor=”green”>
<form runat=”server”>
<center><h4><font color=”blue”> Validation Controls </font> </h4></center>
<table>
<tr>
<td style=color:”yellow”> Enter Your Name : </td>
<td> <asp:textbox id=”idno” runat=”server”/> </td>
<td> <asp:requiredfieldvalidator id=”requiredfielddata”
controltovalidate=”idno” errormessage=”Cannot leave this field blank”
display=”static” runat=”server” /> </td>
</tr>
<tr>
<td style=color:”yellow”> Mode of payment :</td>
<td> <asp:radiobuttonlist id=”radio1" repeatlayout=”flow” runat=”server”>
<asp:listitem style=color:”yellow”>Cash </asp:listitem>
<asp:listitem style=color:”yellow”>Card </asp:listitem>
</asp:radiobuttonlist>
</td>
<td><asp:requiredfieldvalidator id=”requiredfielddata1"
controltovalidate=”radio1" errormessage=”Click either cash or card”
display=”static” runat=”server” />
</td>
</tr>
<tr>
<td style=color:”yellow”> Please select any one from the List : </td>
<td> <asp:dropdownlist id=”cardtype” columns=3 rows=7 runat=”server”>
<asp:listitem> None </asp:listitem>
<asp:listitem> Visa </asp:listitem>
<asp:listitem> Master </asp:listitem>
<asp:listitem> Stc </asp:listitem>
<asp:listitem> Hsbc </asp:listitem>
<asp:listitem> SBI </asp:listitem>
</asp:dropdownlist>
</td>
<td> <asp:requiredfieldvalidator id=”requiredfielddata2"
controltovalidate=”cardtype” errormessage=”Sorry! please select any on e
from above “ display=”static” runat=”server” /> </td>
</tr>
<tr>
<td><br><br><asp:button id=”bt1" text=”Check for validation”
OnClick=”btnclick” runat=”server” style=color:”green” /></td>
</tr>
</table>
<table>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
22
Lab Solutions
<tr>
<td> <asp:label id=”label1" runat=”server” style=color:”pink”/>
</td>
</tr>
</table>
</form>
</html>
Lab 5
Exercise : 1
<html>
<title> Using Request Object </title>
<script language=”c#” runat=”server”>
void btnclick(object s,EventArgs e)
{
if (Page.IsValid==true )
{
result.Text=”Thanks for Registering.Soon u will be Contacted”;
HttpCookie Cookie;
Cookie = new HttpCookie(“cookname”);
Cookie.Values.Add(“uname “,Request.Form[“uname”]);
Response.AppendCookie(Cookie);
Cookie = Request.Cookies[“cookname”];
Response.Write (Cookie.Value + “ has visited the site .”);
}
else
{
result.Text=”Sorry you have to fill these fields”;
}
}
</script>
<form runat=”server” method=”Post” action=”formexp.aspx”>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
23
ASP.NET
Lab 6
Exercise : 1
Lab 7
Exercise : 1
Global.asax:
<form runat=”server”>
<br>
<a href=”useappsession.aspx”>Refresh </a>
<br><br>
<span id=span1 runat=”server”>Using Application variables </span>
</form>
</body>
</html>
<html>
<body>
<form runat=”server”>
<br><br>
<center><h4>This site is under Construction.</h4></center>
<br><br>
<center><a id=”a1" Href=”<%=Application(“gotohp”)%>” runat=”server” >Home
Page </a></center>
</form>
</body>
</html>
Lab 8
Exercise : 1
Lab 9
Exercise : 1
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SQL” %>
<html>
<title> Connecting to Pubs database </title>
<script language=”C#” runat=”server”>
SQLConnection conn;
void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection(
“server=localhost;uid=sa;pwd=;database=master”);
conn.Open();
lbl.Text = “Connection has been established”;
conn.Close();
}
</script>
<body>
<form>
<asp:label id = “lbl” runat=”server” />
</form>
</body>
</html>
Exercise : 2
<html>
<title> Creating the table EMP</title>
<script language=”C#” runat=”server”>
SQLConnection conn;
protected void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection
(“server=localhost;uid=sa;pwd=;database=master”);
}
public void CreTab(Object sender, EventArgs E)
{
String upd = “create table emp(eno integer, ename varchar(20),
salary float)”;
SQLCommand com = new SQLCommand(upd,conn);
com.ActiveConnection.Open();
try
{
com.ExecuteNonQuery();
lb.Text = “The table EMP has been created”;
}
catch (SQLException e)
{
lb.Text = “Error while creating the table”;
}
com.ActiveConnection.Close();
}
</script>
<body>
<form runat=”server”>
<asp:button OnClick=”CreTab” Text=”Create Table”
runat=”server”/><br><br>
<asp:label id=”lb” runat=”server” />
</form>
</body>
</html>
Exercise : 3
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SQL” %>
<html>
<title> Updating a record </title>
<script language=”C#” runat=”server”>
SQLConnection conn;
(“server=localhost;uid=sa;pwd=;database=master”);
}
public void UpdEmp(Object sender, EventArgs E)
{
String upd = “update emp set ename= ‘“ + ename.Text + “‘ where
eno=102";
SQLCommand com = new SQLCommand(upd,conn);
com.ActiveConnection.Open();
try
{
com.ExecuteNonQuery();
lb.Text = “The record has been modified”;
}
catch (SQLException e)
{
lb.Text = “Error while updating”;
}
com.ActiveConnection.Close();
}
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
30
Lab Solutions
</script>
<body>
<form runat=”server”>
Exercise : 4
<html>
<title> Records from Emp </title>
<script language=”C#” runat=”server”>
SQLConnection conn;
protected void Page_Load(Object Src, EventArgs E)
{
conn = new SQLConnection(
“server=sangeetha;uid=sa;pwd=;database=master”);
SQLCommand com = new SQLCommand(“select distinct * from emp where
eno>=100", conn);
conn.Open();
SQLDataReader dr;
com.Execute(out dr);
Response.Write(“<Table width=250 border=1 cellpadding=5>”);
Response.Write(“<TR>”);
Response.Write(“<TD>”);
Response.Write(“<B>ID </B>”);
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
31
ASP.NET
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(“<B>Name </B>”);
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(“<B>Salary </B>”);
Response.Write(“</TD>”);
Response.Write(“</TR>”);
while (dr.Read())
{
Response.Write(“<TR>”);
Response.Write(“<TD>”);
Response.Write(dr[“eno”].ToString() + “ “);
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(dr[“ename”].ToString() + “ “);
Response.Write(“</TD>”);
Response.Write(“<TD>”);
Response.Write(dr[“sal”].ToString() + “ “);
Response.Write(“</TD>”);
Response.Write(“</TR>”);
}
conn.Close();
}
</script>
</html>
Lab 10
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
32
Lab Solutions
Exercise : 1
strconn=”server=localhost;uid=sa;pwd=;database=model”;
con = new SQLConnection(strconn);
</body>
</html>
Exercise : 2
<%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SQL” %>
<script language=”c#” runat=”server”>
void Page_Load(Object o, EventArgs e)
{
DataSet ds;
SQLConnection con;
SQLDataSetCommand com;
string strconn;
string strSQL;
strconn=”server=localhost;uid=sa;pwd=;database=model”;
con = new SQLConnection(strconn);
strSQL=”select distinct ename from emps”;
com = new SQLDataSetCommand(strSQL,con);
ds = new DataSet();
com.FillDataSet(ds, “emps”);
st.DataSource=ds.Tables[“emps”].DefaultView;
st.DataBind();
st2.DataSource=ds.Tables[“emps”].DefaultView;
st2.DataBind();
st3.DataSource=ds.Tables[“emps”].DefaultView;
st3.DataBind();
}
</script>
<html><head>
<title>Radio Buttons from States</title>
</head>
<body bgcolor=”#FFFFFF”>
<h3><font face=”Verdana”>State(s) to Query</font></h3>
<hr>
repeatcolumns 5, repeatdirection horizontal, repeatlayout table<br>
<ASP:radiobuttonList
repeatcolumns=”5" repeatdirection=”horizontal” repeatlayout=”table”
id=”st” datatextfield=”ename” DataValueField=”ename” runat=”server”/>
<br>
<hr>
repeatcolumns 5, repeatdirection vertical, repeatlayout table<br>
<ASP:radiobuttonList
repeatcolumns=”5" repeatdirection=”vertical” repeatlayout=”table”
id=”st2" datatextfield=”ename” DataValueField=”ename” runat=”server”/>
<hr>
repeatlayout flow<br>
<ASP:radiobuttonList
repeatlayout=”flow”
id=”st3" datatextfield=”ename” DataValueField=”ename” runat=”server”/>
<hr>
</body>
</html>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
34
Lab Solutions
Exercise : 3
strconn=”server=localhost;uid=sa;pwd=;database=model”;
con = new SQLConnection(strconn);
zp.DataSource=ds.Tables[“emps”].DefaultView;
zp.DataBind();
}
</script>
<html><head>
<title>Grid of New York Data</title>
</head>
<body bgcolor=”#FFFFFF”>
<h3><font face=”Verdana”>No, Name, Salary Lists of emps Table</font></h3>
<asp:TableRow>
<asp:TableCell>Name</asp:TableCell>
<asp:TableCell><ASP:DropDownList id=”st” datatextfield=”ename”
DataValueField=”ename” runat=”server”/></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Salary</asp:TableCell>
<asp:TableCell><ASP:DropDownList id=”zp” datatextfield=”esal”
DataValueField=”esal” runat=”server”/></asp:TableCell>
</asp:TableRow>
</asp:Table>
</body>
</html>
Lab 11
Exercise : 1
<html>
<head>
<title> Details of products </title>
<script language=”C#” runat=”server”>
void Page_Load(Object sender, EventArgs e) {
Page.DataBind();
}
int ID{
get {
return 10;
}
}
string Name{
get {
return “Wheat”;
}
}
float Price{
get {
return 14.25f;
}
}
int Qty{
get {
return 1000;
}
}
</script>
</head>
<body>
<form runat=server>
Product ID: <b><%# ID %></b><br>
Product Name: <b><%# Name %></b><br>
Price: <b><%# Price %></b><br>
Quantity: <b><%# Qty %></b>
</form>
</body>
</html>
Exercise : 2
<html>
<head>
<title> Binding to a label </title>
<script language=”C#” runat=”server”>
void Btn_Click(Object sender, EventArgs e) {
Page.DataBind();
}
</script>
</head>
<body>
<form runat=server>
<asp:RadioButtonList id=”Flower” repeatcolumns=2 runat=”server” size=3>
<asp:ListItem>Jasmine</asp:ListItem>
<asp:ListItem>Rose</asp:ListItem>
<asp:ListItem>Lotus</asp:ListItem>
<asp:ListItem>Lily</asp:ListItem>
<asp:ListItem>Daisy</asp:ListItem>
<asp:ListItem>Dahlia</asp:ListItem>
</asp:RadioButtonList>
<br><br>
<asp:button Text=”Submit” OnClick=”Btn_Click” runat=server/>
<br><br>
Your favourite flower is: <asp:label text=’<%# Flower.SelectedItem.Text %>’
runat=server/>
</form>
</body>
</html>
Exercise : 3
connStr=”server=localhost;uid=sa;database=master”;
conn = new SQLConnection(connStr);
</script>
<body>
<form runat=server>
<asp:Label id=”lbl” text=”Following is the list of available
products: “ runat=”server” />
<br><br>
<asp:CheckBoxList id=”prods” runat=”server” />
</form>
</body>
</html>
Lab 12
Exercise : 1
<head>
<script language=”c#” runat=”server” >
String conn;
DataGrid1.DataSource = ds.Tables[“customer”].DefaultView;
DataGrid1.DataBind();
}
</script>
</script>
</head>
<form runat=”server”>
<h4> Sorting Datagrid Control </h4>
<asp:Datagrid id=”DataGrid1" runat=”server” />
</form>
</body>
</html>
Exercise : 2
if (!IsPostBack)
BindGrid(“CustomerID”);
}
void dbsort(object src,DataGridSortCommandEventArgs e)
{
BindGrid(e.SortField);
}
void BindGrid(String sortfield)
{
</script>
</head>
<form runat=”server”>
<h4> Sorting Datagrid Control </h4>
<asp:Datagrid id=”DataGrid1" onsortcommand=”dbsort” allowsorting=”true”
runat=”server” autogeneratecolumns=”true”/>
</form>
</body>
</html>
Exercise : 3
</script>
<form runat=”server”>
<h3> Paging Feature </h3>
<br>
<ASP:DataGrid id=”dg” runat=”server” AllowPaging=”True” PageSize=”3"
PageCount=”1"
PagerStyle-Mode=”NumericPages”
PagerStyle-HorizontalAlign=”Right”
OnPageIndexChanged=”changePage”
/>
</form>
Lab 13
Exercise : 1
<html>
<head><title>Tracing Events</title></head>
<body>
<% Trace.Warn( “user”, “page mid rendering event!” ); %>
<form runat=”server”>
<asp:label id=”myLabel” runat=”server”/>
<p>
<b>Enter Your Name:</b>
<br>
<asp:textbox id=”yourName” runat=”Server” />
<p>
<b>Pick Your Favorite technology:</b>
<br>
<asp:dropdownlist id=”favTech” runat=”server”>
<asp:listitem>ASP.NET</asp:listitem>
<asp:listitem>ADO.NET</asp:listitem>
<asp:listitem>C#</asp:listitem>
</asp:dropdownlist>
<p>
<b> Comments:</b>
<br>
<asp:textbox id=”comments” textmode=”multiline” cols=”20" rows=”5"
runat=”Server” />
<p>
<asp:button text=”Submit!” onClick=”test” runat=”server” />
</form>
</body>
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
43
ASP.NET
</html>
Exercise : 2
<form runat=”server”>
<asp:button id=”button1" onclick=”button1_click”
text=”click me” runat=”server” />
</form>
</html>
Exercise : 3
<html>
<script language=”C#” runat=”server”>
void Page_Load(Object Src, EventArgs E)
{
if(Trace.IsEnabled)
{
SQLConnection con = new
SQLConnection(“server=localhost;uid=sa;pwd=”);
Lab 14
Exercise : 1
<script language=”C#” runat=”server”>
void Page_Load(Object sender, EventArgs E) {
if(Page.IsPostBack)
{
display.Text=”You have selected the color: “ +
col.SelectedItem.Text ;
}
}
Exercise : 2
Exercise : 3
<body>
<form id=”frm” runat=”server”>
<User:Login id=”log” runat=”server”/>
</form>
</body>
</html>
Lab 15
Exercise : 1
//calcomp.cs
using System;
namespace calcomp
{
public class cal
Centre for Information Technology and Engineering, Manonmaniam Sundaranar University
49
ASP.NET
{
public int add(String t1,String t2)
{
int a=Int32.Parse(t1);
int b=Int32.Parse(t2);
return a+b;
}
public int sub(String t1,String t2)
{
int a=Int32.Parse(t1);
int b=Int32.Parse(t2);
return a-b;
}
}
}
//calapp.aspx
<html>
<script language=”C#” runat=”server”>
void button_add(Object Src, EventArgs E)
{
cal o1=new cal();
int c=o1.add(t1.Text,t2.Text);
Response.Write(“The value of a+b is “+c.ToString());
}
void button_sub(Object Src, EventArgs E)
{
cal o1=new cal();
int c=o1.sub(t1.Text,t2.Text);
Response.Write(“The value of a-b is “+c.ToString());
}
</script>
<body>
<form runat=server>
<h5>Enter the Value of a: </h5>
<asp:textbox id=t1 Text=”0" runat=server/>
<br>
<h5>Enter the Value of b: </h5>
<asp:textbox id=t2 Text=”0" runat=server/>
<p>
<asp:Button id=b1 text=”Add” OnClick=button_add runat=server/>
<asp:Button id=b2 text=”Subtract” OnClick=button_sub runat=server/>
</form>
</html>
Exercise : 2
//abscomp.cs
using System;
namespace abscomp
{
abstract public class Absclass
{
abstract public String method();
}
}
//dercomp
using System;
using abscomp;
namespace dercomp
{
public class derived:Absclass
{
public override String method()
{
return (“Abstract Class”);
}
}
}
//absapp.aspx
<%@ Import Namespace=”dercomp” %>
<html>
<script language=”C#” runat=”server”>
public void Page_Load(Object sender, EventArgs E)
{
derived d1=new derived();
String s=d1.method();
Response.Write(s.ToString());
}
</script>
</html>
Exercise : 3
//indcomp.cs
namespace indcomp
{
public class IndexerClass
{
int [] a = new int[100];
public int this [int index]
{
get
{
if (index < 0 || index >= 100)
return 0;
else
return a[index];
}
set
{
if (!(index < 0 || index >= 100))
a[index] = value;
}
}
}
}
//indapp.aspx
<html>
<script language=”C#” runat=”server”>
public void Page_Load(Object sender, EventArgs E)
{
IndexerClass b = new IndexerClass();
b[2] = 30;
b[6] = 35;
b[4]=40;
b[7]=10;
for (int i=0; i<=10; i++)
{
Response.Write(“Indexer Element at “+ i+ “is “ + b[i]);
Response.Write(“<br>”);
}
}
</script>
</html>
YZ