Department of Computer Applications, SRM University: VIJAY BHARATH A, Asst. Prof (SR.G)
Department of Computer Applications, SRM University: VIJAY BHARATH A, Asst. Prof (SR.G)
VIJAY BHARATH A , Asst. Prof (Sr.G) APRIL 2011 [Pick the date]
INDEX
Ex. No
Title
Marks (10)
Signature
2 3
4. calendar control
a b c d
Display messages in a calendar control Display vacation in a calendar control Selected day in a calendar control using style Difference between two calendar dates
5. Treeview control
a b Treeview control and datalist Treeview operations
Validation controls
Ex.No
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Title
Query textbox and Displaying records Display records by using database Datalist link control Databinding using dropdownlist control Inserting record into a database Deleting record into a database Databinding using datalist control Datalist control templates Databinding using datagrid Datagrid control template Datagrid hyperlink Datagrid button column Datalist event Datagrid paging Creating own table format using datagrid
Marks (10)
Signature
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 352px; position: absolute; top: 16px" Text="Factorial"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 248px; position: absolute; top: 88px" Text="Enter the number"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 102; left: 448px; position: absolute; top: 88px" AutoPostBack="True"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 352px; position: absolute; top: 176px" Text="Generate" Width="88px" /> <asp:Label ID="Label3" runat="server" Style="z-index: 105; left: 368px; position: absolute; top: 272px"></asp:Label> </div> </form> </body> </html>
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim a As Double Dim f As Double f = 1 i = 1 a = TextBox1.Text While i <= a f = f * i i = i + 1 End While Label3.Text = f & "unit" End Sub End Class
Sample I/O:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 400px; position: absolute; top: 24px" Text="Money Conversion"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 288px; position: absolute; top: 96px" Text="Select currency Type"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 102; left: 288px; position: absolute; top: 160px" Text="Enter the Amount"></asp:Label> <asp:Label ID="Label4" runat="server" Style="z-index: 103; left: 296px; position: absolute; top: 232px" Text="Select currency Type"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 104; left: 496px; position: absolute; top: 160px" AutoPostBack="True"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 105; left: 424px; position: absolute; top: 280px" Text="Convert" Width="80px" /> <asp:Label ID="Label5" runat="server" Style="z-index: 106; left: 432px; position: absolute;
top: 344px"></asp:Label> <asp:DropDownList ID="DropDownList1" runat="server" Style="z-index: 107; left: 496px; position: absolute; top: 96px"> <asp:ListItem>Rupees</asp:ListItem> <asp:ListItem>Doller</asp:ListItem> <asp:ListItem>Zen</asp:ListItem> <asp:ListItem>Yen</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" Style="z-index: 109; left: 512px; position: absolute; top: 216px"> <asp:ListItem>Rupees</asp:ListItem> <asp:ListItem>Doller</asp:ListItem> <asp:ListItem>Zen</asp:ListItem> <asp:ListItem>Yen</asp:ListItem> </asp:DropDownList>
Code:
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Double a = TextBox1.Text If DropDownList1.SelectedItem.Value = "Rupees" And DropDownList2.SelectedItem.Value = "Doller" Then Label5.Text = a * 45 & "$" ElseIf DropDownList1.SelectedItem.Value = "Rupees" And DropDownList2.SelectedItem.Value = "Zen" Then Label5.Text = a * 43 & "Z" ElseIf DropDownList1.SelectedItem.Value = "Rupees" And DropDownList2.SelectedItem.Value = "Yen" Then Label5.Text = a * 42 & "Y" ElseIf DropDownList1.SelectedItem.Value = "Doller" And DropDownList2.SelectedItem.Value = "Rupees" Then Label5.Text = a * 33 & "R" ElseIf DropDownList1.SelectedItem.Value = "Doller" And DropDownList2.SelectedItem.Value = "Zen" Then Label5.Text = a * 32 & "Z" ElseIf DropDownList1.SelectedItem.Value = "Doller" And DropDownList2.SelectedItem.Value = "Yen" Then Label5.Text = a / 31 & "y" ElseIf DropDownList1.SelectedItem.Value = "Zen" And DropDownList2.SelectedItem.Value = "Rupees" Then Label5.Text = a * 45 & "R" ElseIf DropDownList1.SelectedItem.Value = "Zen" And DropDownList2.SelectedItem.Value = "Doller" Then Label5.Text = a * 46 & "$"
ElseIf DropDownList1.SelectedItem.Value = "Zen" And DropDownList2.SelectedItem.Value = "Yen" Then Label5.Text = a * 47 & "Y" ElseIf DropDownList1.SelectedItem.Value = "Yen" And DropDownList2.SelectedItem.Value = "Rupees" Then Label5.Text = a / 34 & "R" ElseIf DropDownList1.SelectedItem.Value = "Yen" And DropDownList2.SelectedItem.Value = "Doller" Then Label5.Text = a / 35 & "$" ElseIf DropDownList1.SelectedItem.Value = "Yen" And DropDownList2.SelectedItem.Value = "Zen" Then Label5.Text = a / 36 & "Z" Else : DropDownList1.SelectedItem.Value = DropDownList2.SelectedItem.Value = "Zen" MsgBox("You Select Same Currency")
Sample I/O:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 336px; position: absolute; top: 24px" Text="Quadretic Equation"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 248px; position: absolute; top: 112px" Text="Enter the value of a"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 102; left: 248px; position: absolute; top: 176px" Text="Enter the value of b"></asp:Label> <asp:Label ID="Label4" runat="server" Style="z-index: 103; left: 248px; position: absolute; top: 240px" Text="Enter the value of c"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" Style="z-index: 104; left: 488px; position: absolute; top: 104px"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True" Style="z-index: 105; left: 488px; position: absolute; top: 176px"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" AutoPostBack="True" Style="z-index: 106;
left: 488px; position: absolute; top: 240px"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 107; left: 408px; position: absolute; top: 320px" Text="Generate" Width="104px" /> <asp:Label ID="Label5" runat="server" Style="z-index: 108; left: 432px; position: absolute; top: 400px"></asp:Label> <asp:Label ID="Label6" runat="server" Style="z-index: 110; left: 432px; position: absolute; top: 464px"></asp:Label>
Code:
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Double Dim b As Double Dim c As Double Dim s As Double Dim x1 As Double Dim x2 As Double a = TextBox1.Text b = TextBox2.Text c = TextBox3.Text s = Math.Sqrt(b * b - 4 * a * c) If (b * b - 4 * a * c) = 0 Then Label5.Text = "Roots are Equal" x1 = (-b + s) / 2 * a x2 = (-b - s) / 2 * a Label6.Text = "The Roots : " & x1 ElseIf (b * b - 4 * a * c) < 0 Then Label5.Text = "The Roots are Imaginary" Else Label5.Text = "The Roots are Not Equal" x1 = (-b + s) / 2 * a x2 = (-b - s) / 2 * a Label6.Text = "The Roots " & x1 & "or" & x2 End If End Sub
Sample I/O:
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 400px; position: absolute; top: 16px" Text="Temperature Conversion"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 168px; position: absolute; top: 128px" Text="Select one option"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 102; left: 248px; position: absolute; top: 320px" Text="Enter the Temperture"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 103; left: 472px; position: absolute; top: 312px" AutoPostBack="True"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 104; left: 448px; position: absolute; top: 408px" Text="Generate" Width="96px" /> <asp:RadioButton ID="RadioButton1" runat="server" Style="z-index: 105; left: 448px;
position: absolute; top: 176px" GroupName="a" Text=" Fahrenheit to celsius" /> <asp:RadioButton ID="RadioButton2" runat="server" Style="z-index: 106; left: 448px; position: absolute; top: 224px" GroupName="a" Text=" Celsius to Fahrenheit" /> <asp:Label ID="Label4" runat="server" Style="z-index: 108; left: 472px; position: absolute; top: 480px"></asp:Label>
Code:
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a As Double Dim f As Double Dim c As Double a = TextBox1.Text If RadioButton1.Checked Then c = (a - 32) * 5 / 9 Label4.Text = c & "f" ElseIf RadioButton2.Checked Then f = (a * 9 / 5) + 32 Label4.Text = f & "c" Else MsgBox("Select one Option") End If End Sub End class
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Login ID="Login1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px"> </asp:Login>
Code:
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate If Login1.UserName = "Database" And Login1.Password = "Jaiswal" Then MsgBox("You are successfully Logged in") Else MsgBox("Error:Loggedin") End If If Application("i") = 3 Then MsgBox("You are Blocked") Login1.Enabled = False End If End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Application("i") = Int(Application("i") + 1) If Application("i") > 3 Then Application("i") = 0 End If End Sub End Class
Global Application:
<%@ Application Language="VB" %> <script runat="server"> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application shutdown End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error occurs End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a session ends. ' Note: The Session_End event is raised only when the sessionstate mode ' is set to InProc in the Web.config file. If session mode is set to StateServer ' or SQLServer, the event is not raised. End Sub
</script>
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 352px; position: absolute; top: 16px" Text="View state"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 192px; position: absolute; top: 80px" Text="Enter Item Name"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" Style="z-index: 102; left: 400px; position: absolute; top: 80px"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 392px; position: absolute; top: 144px" Text="Submit" Width="80px" /> <asp:Label ID="Label3" runat="server" Style="z-index: 104; left: 400px; position: absolute; top: 192px" Text="Label"></asp:Label> <asp:Label ID="Label4" runat="server" Style="z-index: 105; left: 336px; position: absolute; top: 232px" Text="Application State"></asp:Label> <asp:Label ID="Label5" runat="server" Style="z-index: 106; left: 248px; position: absolute;
top: 312px" Text="No of last visit"></asp:Label> <asp:Label ID="Label6" runat="server" Style="z-index: 107; left: 488px; position: absolute; top: 312px" Text="Label"></asp:Label> <asp:Label ID="Label7" runat="server" Style="z-index: 108; left: 384px; position: absolute; top: 376px" Text="Session state"></asp:Label> <asp:Label ID="Label8" runat="server" Style="z-index: 110; left: 392px; position: absolute; top: 448px"></asp:Label>
Code:
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Application("visits") = Int(Application("visits") + 1) Label6.Text = Application("visits") Label8.Text = Session("My text").ToString End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim txt As String = TextBox1.Text ViewState.Add("Item", txt)
Dim Item As String = ViewState("Item").ToString Label3.Text = Item End Sub End Class
Global Application:
] <%@ Application Language="VB" %> <script runat="server"> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application startup Application("visits") = 0 End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application shutdown End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when an unhandled error occurs End Sub Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a new session is started Session("My text") = "I am the user" End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode ' is set to InProc in the Web.config file. If session mode is set to StateServer ' or SQLServer, the event is not raised. End Sub </script>
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/XMLFile.xml" Height="536px" Style="z-index: 100; left: 0px; position: absolute; top: 0px" Width="464px" />
Code:
<?xml version="1.0" encoding="utf-8" ?> <Advertisements> <Ad> <ImageUrl>.\image\p1.jpg</ImageUrl> <NavigateUrl>www.pepsi.com</NavigateUrl> <AlternativeText>Pepsi</AlternativeText>
<Keyword>softdrink</Keyword> <Impression>2</Impression> </Ad> <Ad> <ImageUrl>.\image\p2.jpg</ImageUrl> <NavigateUrl>www.Excel.com</NavigateUrl> <AlternativeText>Excel</AlternativeText> <Keyword>softdrink</Keyword> <Impression>2</Impression> </Ad> <Ad> <ImageUrl>.\image\p3.jpg</ImageUrl> <NavigateUrl>www.7up.com</NavigateUrl> <AlternativeText>7up</AlternativeText> <Keyword>softdrink</Keyword> <Impression>2</Impression> </Ad> <Ad> <ImageUrl>.\image\p4.jpg</ImageUrl> <NavigateUrl>www.Mirinda.com</NavigateUrl> <AlternativeText>Mirinda</AlternativeText> <Keyword>softdrink</Keyword> <Impression>2</Impression> </Ad> </Advertisements>
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px"></asp:Calendar> </div> </form> </body> </html>
Code:
Partial Class _Default Inherits System.Web.UI.Page Dim Holidays(13, 32)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Holidays(10, 12) = "Birthdays" Holidays(10, 15) = "Aniversary" End Sub
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender If e.Day.IsOtherMonth Then e.Cell.Controls.Clear() Else Dim adate As Date = e.Day.Date Dim aHolidays As String = Holidays(adate.Month, adate.Day) If (Not aHolidays Is Nothing) Then Dim alabel As New Label() alabel.Text = "<br>" & aHolidays e.Cell.Controls.Add(alabel) End If End If End Sub End Class
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px"></asp:Calendar> </div> </form> </body> </html>
Code:
Partial Class _Default Inherits System.Web.UI.Page Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender 'Display vocationdates in yellow color with purple borderstyle' Dim vocationstyle As New Style() With vocationstyle .BackColor = System.Drawing.Color.Yellow .BorderColor = System.Drawing.Color.Black .BorderWidth = New Unit(3) End With 'Display weekendstyle in green color' Dim weekendstyle As New Style() weekendstyle.BackColor = System.Drawing.Color.SpringGreen 'vacation start from nov23, If ((e.Day.Date >= New Date(2009, 11, 23)) And (e.Day.Date <= New Date(2009, 11, 30))) Then e.Cell.ApplyStyle(vocationstyle) ElseIf (e.Day.IsWeekend) Then e.Cell.ApplyStyle(weekendstyle) End If End Sub
Sample I/O:
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Style="z-index: 100; left: 200px; position: absolute; top: 0px"></asp:Calendar> <asp:Label ID="Label1" runat="server" Style="z-index: 101; left: 208px; position: absolute; top: 224px" Text="Label"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 105; left: 840px; position: absolute; top: 224px" Text="Label"></asp:Label> <asp:Calendar ID="Calendar2" runat="server" Style="z-index: 103; left: 688px; position: absolute; top: 0px"></asp:Calendar> <asp:Calendar ID="Calendar3" runat="server" Style="z-index: 104; left: 400px; position: absolute; top: 368px"></asp:Calendar> <br /><br /> <br /> FROM TO<br />
Code:
Partial Class _Default Inherits System.Web.UI.Page Dim Holidays(13, 32) Protected Sub Calendar3_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar3.DayRender 'Display vacationstyle dates in yellow boxes with purple borders' Dim vacationstyle As New Style() With vacationstyle .BackColor = System.Drawing.Color.Yellow .BorderColor = System.Drawing.Color.Purple .BorderWidth = New Unit(3) End With 'Display weekenddates in green boxes' Dim weekendstyle As New Style() weekendstyle.BackColor = System.Drawing.Color.Green If ((e.Day.Date >= Calendar1.SelectedDate) And (e.Day.Date <= Calendar2.SelectedDate)) Then e.Cell.ApplyStyle(vacationstyle) ElseIf (e.Day.IsWeekend) Then e.Cell.ApplyStyle(weekendstyle) End If If e.Day.IsOtherMonth Then e.Cell.Controls.Clear() Else
Dim aDate As Date = e.Day.Date Dim aHolidays As String = Holidays(aDate.Month, aDate.Day) If (Not aHolidays Is Nothing) Then Dim alabel As Label = New Label() alabel.Text = "<br>" & aHolidays e.Cell.Controls.Add(alabel)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Holidays(8, 15) = "IndependenceDay" Holidays(1, 26) = "RepublicDay" Holidays(10, 12) = "Birthday" End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged Label1.Text = Calendar1.SelectedDate End Sub
Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar2.SelectionChanged Label2.Text = Calendar2.SelectedDate End Sub End Class
Sample I/O:
--------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to display the Difference between the two dates in the calendar.
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Calendar ID="Calendar1" runat="server" Style="z-index: 100; left: 72px; position: absolute; top: 8px"></asp:Calendar> <asp:Button ID="Button1" runat="server" Style="z-index: 101; left: 432px; position: absolute; top: 280px" Text="Difference" Width="120px" /> <asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 368px; position: absolute; top: 360px" Text="Label" Width="56px"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 103; left: 456px; position: absolute; top: 360px" Text="Label" Width="64px"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 106; left: 544px; position: absolute; top: 360px" Text="Label" Width="56px"></asp:Label>
<asp:Calendar ID="Calendar2" runat="server" Style="z-index: 105; left: 536px; position: absolute; top: 8px"></asp:Calendar> <br /> THE DIFFERENCE BETWEEN TWO DATES<br /> <br /> <br /> <br />
Code:
Imports system.data.sqlclient Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If floor(Calendar2.SelectedDate > Calendar1.SelectedDate) Then Dim a As double = Math.abs(Calendar2.SelectedDate Calendar1.SelectedDate).TotalDays Dim y As Double = a / 365 Label1.Text = floor(y) & "YEARS" Dim x As Double= a mode 365 Dim m As Integer = x / 31 Label2.Text =floor(m) & "MONTHS"
Dim d As Integer = x mode 31 Label3.Text = floor(d) & "DAYS" Else MsgBox("Invalid date") End If End Sub End Class
Sample I/O:
--------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to perform Tree view operation using data list.
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TreeView ID="TreeView1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px"> <Nodes> <asp:TreeNode Text="SRM UNIVERSITY" Value="SRM UNIVERSITY" Checked="True" ShowCheckBox="True"> <asp:TreeNode Text="Art & science" Value="Art & science" ShowCheckBox="True"> <asp:TreeNode Text="BA" Value="BA" ShowCheckBox="True"></asp:TreeNode> <asp:TreeNode Text="MA" Value="MA" ShowCheckBox="True"></asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Science & Humanity" Value="Science & Humanity" ShowCheckBox="True"> <asp:TreeNode Text="Bsc" Value="Bsc" ShowCheckBox="True"></asp:TreeNode>
<asp:TreeNode Text="Msc" Value="Msc" ShowCheckBox="True"></asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Computer science" Value="Computer science" ShowCheckBox="True"> <asp:TreeNode Text="CSE" Value="CSE" ShowCheckBox="True"></asp:TreeNode> <asp:TreeNode Text="BCA" Value="BCA" ShowCheckBox="True"></asp:TreeNode> <asp:TreeNode Text="MCA" Value="MCA" ShowCheckBox="True"></asp:TreeNode> </asp:TreeNode> </asp:TreeNode> </Nodes> </asp:TreeView> </div> <asp:DataList ID="DataList1" runat="server" Style="z-index: 101; left: 264px; position: absolute; top: 424px"> <HeaderTemplate > The following nodes are checked: </HeaderTemplate> <ItemTemplate > <%# Eval("Text") %> </ItemTemplate> </asp:DataList> <asp:Button ID="Button1" runat="server" Style="z-index: 103; left: 304px; position: absolute; top: 272px" Text="Fix it" Width="88px" /> </form> </body> </html>
Code:
Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim checkednodes As TreeNodeCollection = TreeView1.CheckedNodes DataList1.DataSource = checkednodes DataList1.DataBind() End Sub
Sample I/O:
-----------------------------------------------------------------------------------------------------------------------------------
Design:
Source:
<!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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TreeView ID="TreeView1" runat="server" Style="z-index: 100; left: 432px; position: absolute; top: 32px"> <Nodes> <asp:TreeNode Checked="True" Expanded="True" ShowCheckBox="True" Text="SRM UNIVERSITY" Value="SRM UNIVERSITY"> <asp:TreeNode Expanded="False" ShowCheckBox="True" Text="Art & science" Value="Art & science"> <asp:TreeNode ShowCheckBox="True" Text="BA" Value="BA"></asp:TreeNode> <asp:TreeNode ShowCheckBox="True" Text="MA" Value="MA"></asp:TreeNode> </asp:TreeNode> <asp:TreeNode Expanded="False" ShowCheckBox="True" Text="Science & Humanity" Value="Science & Humanity">
<asp:TreeNode ShowCheckBox="True" Text="Bsc" Value="Bsc"></asp:TreeNode> <asp:TreeNode ShowCheckBox="True" Text="Msc" Value="Msc"></asp:TreeNode> </asp:TreeNode> <asp:TreeNode Expanded="False" ShowCheckBox="True" Text="Computer science" Value="Computer science"> <asp:TreeNode ShowCheckBox="True" Text="CSE" Value="CSE"></asp:TreeNode> <asp:TreeNode ShowCheckBox="True" Text="BCA" Value="BCA"></asp:TreeNode> <asp:TreeNode ShowCheckBox="True" Text="MCA" Value="MCA"></asp:TreeNode> </asp:TreeNode> </asp:TreeNode> </Nodes> </asp:TreeView> </div> </form> </body> </html>
Code:
Partial Class _Default Inherits System.Web.UI.Page
End Sub
Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged Dim value As String = TreeView1.SelectedNode.Value Dim path As String = TreeView1.SelectedNode.ValuePath Response.Write("The value select was" & value & "<br>") Response.Write("The value path is " & value & "<br>") End Sub
Protected Sub TreeView1_TreeNodeCheckChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeCheckChanged Dim value As String = e.Node.Value Response.Write("The value collapsed was" & value & "<br>") End Sub
Protected Sub TreeView1_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded Dim value As String = e.Node.Value Response.Write("The value collapsed was" & value & "<br>") End Sub End Class
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 384px; position: absolute; top: 16px" Text="Registation form"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 248px; position: absolute; top: 72px" Text="Name"></asp:Label> <asp:Label ID="Label3" runat="server" Style="z-index: 102; left: 248px; position: absolute; top: 120px" Text="Reg_no"></asp:Label> <asp:Label ID="Label4" runat="server" Style="z-index: 103; left: 240px; position: absolute; top: 176px" Text="Date_Of_Birth"></asp:Label> <asp:Label ID="Label5" runat="server" Style="z-index: 104; left: 240px; position: absolute; top: 232px" Text="Department"></asp:Label> <asp:Label ID="Label6" runat="server" Style="z-index: 105; left: 248px; position: absolute; top: 296px" Text="Address"></asp:Label> <asp:Label ID="Label7" runat="server" Style="z-index: 106; left: 240px; position: absolute;
top: 352px" Text="Phone number"></asp:Label> <asp:Label ID="Label8" runat="server" Style="z-index: 107; left: 240px; position: absolute; top: 392px" Text="personal phone no"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 108; left: 456px; position: absolute; top: 72px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 109; left: 456px; position: absolute; top: 120px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" Style="z-index: 110; left: 456px; position: absolute; top: 176px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" Style="z-index: 111; left: 456px; position: absolute; top: 232px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox5" runat="server" Style="z-index: 112; left: 456px; position: absolute; top: 288px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox6" runat="server" Style="z-index: 113; left: 448px; position: absolute; top: 392px" AutoPostBack="True"></asp:TextBox> <asp:TextBox ID="TextBox7" runat="server" Style="z-index: 114; left: 448px; position: absolute; top: 448px" AutoPostBack="True"></asp:TextBox> <asp:Label ID="Label9" runat="server" Style="z-index: 115; left: 248px; position: absolute; top: 448px" Text="Home phone no"></asp:Label>
<asp:Label ID="Label10" runat="server" Style="z-index: 116; left: 256px; position: absolute; top: 512px" Text="Email_id"></asp:Label>
<asp:TextBox ID="TextBox8" runat="server" Style="z-index: 117; left: 448px; position: absolute; top: 504px" AutoPostBack="True"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" Style="z-index: 118; left: 672px; position: absolute; top: 72px">Must enter name</asp:RequiredFieldValidator> <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="RangeValidator" Style="z-index: 119; left: 672px; position: absolute; top: 120px" ControlToValidate="TextBox2" MaximumValue="35208182" MinimumValue="35208001">Must be enter between 35208001 to 35208182</asp:RangeValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox4" ErrorMessage="RequiredFieldValidator" Style="z-index: 120; left: 672px; position: absolute; top: 232px">Must enter dept</asp:RequiredFieldValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox3" ErrorMessage="RequiredFieldValidator" Style="z-index: 121; left: 680px; position: absolute; top: 184px">Must enter date of birth</asp:RequiredFieldValidator> <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBox6" ControlToValidate="TextBox7" ErrorMessage="CompareValidator" Style="z-index: 122; left: 664px; position: absolute; top: 400px"></asp:CompareValidator> <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="TextBox5" ErrorMessage="CustomValidator" Style="z-index: 123; left: 664px; position: absolute;
top: 288px">Must enter address</asp:CustomValidator> <asp:Button ID="Button1" runat="server" Style="z-index: 124; left: 392px; position: absolute; top: 576px" Text="Register" Width="104px" /> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox8" Display="None" ErrorMessage="RegularExpressionValidator" Style="zindex: 126; left: 656px; position: absolute; top: 512px" ValidationExpression="(\(\d{3}\)|\d{3})?\d{8}"></asp:RegularExpressionValidator>
Code:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If IsValid Then Label9.Enabled = False TextBox7.Enabled = False End If
Sample I/O:
--------------------------------------------------------------------------------------------------------------------------------------------
AIM: Write a Program to bind data in a multiline textbox by querying in another textbox.
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txtQuery" TextMode="MultiLine" Columns="80" Rows="4" Runat="Server" /> <br> <asp:Button ID="Button1" Text="Execute Query" OnClick="Button_Click" Runat="Server" /> <p> <asp:TextBox
Code:
Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Button_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conPubs As SqlConnection Dim cmdSelect As SqlCommand Dim dtrResults As SqlDataReader Dim intField As Integer
conPubs.Open() cmdSelect = New SqlCommand(txtQuery.Text, conPubs) dtrResults = cmdSelect.ExecuteReader() txtResults.Text = "" While dtrResults.Read() txtResults.Text &= vbNewLine For intField = 0 To dtrResults.FieldCount - 1 txtResults.Text &= dtrResults(intField).ToString().PadRight(15) Next End While dtrResults.Close() conPubs.Close()
Sample I/O:
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 328px; position: absolute; top: 24px" Text="Another PhoneLookup"></asp:Label> <asp:Label ID="Label2" runat="server" Style="z-index: 101; left: 344px; position: absolute; top: 80px" Text="Au_fname"></asp:Label> <asp:TextBox ID="Au_fname" runat="server" Style="z-index: 102; left: 304px; position: absolute; top: 128px"></asp:TextBox> <asp:Label ID="Label3" runat="server" Style="z-index: 103; left: 344px; position: absolute; top: 184px" Text="Au_lname"></asp:Label> <asp:TextBox ID="Au_lname" runat="server" Style="z-index: 104; left: 304px; position: absolute; top: 248px"></asp:TextBox>
<asp:Label ID="Label4" runat="server" Style="z-index: 105; left: 280px; position: absolute; top: 416px" Text="phone"></asp:Label> <asp:Button ID="Button1" runat="server" Style="z-index: 106; left: 360px; position: absolute; top: 312px" Text="lookup" /> <asp:Label ID="label5" runat="server" Style="z-index: 108; left: 352px; position: absolute; top: 416px" Text="Label" Width="104px">
</asp:Label>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conpubs As SqlConnection Dim strselect As String Dim cmdselect As SqlCommand
conpubs = New SqlConnection(constr) strselect = "select phone from Author where Au_fname=@Au_fname And Au_lname=@Au_lname" cmdselect = New SqlCommand(strselect, conpubs) cmdselect.Parameters.Add("@Au_fname", Au_fname.Text) cmdselect.Parameters.Add("@Au_lname", Au_lname.Text) conpubs.Open() label5.Text = cmdselect.ExecuteScalar() conpubs.Close()
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="dtrlstAuthor" runat="server" Style="z-index: 16; left: 0px; position: absolute; top: 0px"> <ItemTemplate > <asp:LinkButton ID ="linkbutton1" %>'
</div>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindDataList() End If End Sub Sub BindDatalist() Dim conpubs As SqlConnection Dim cmdselect As SqlCommand Dim dtrAuthor As SqlDataReader conpubs = New SqlConnection(constr) conpubs.Open() cmdselect = New SqlCommand("Select * from Author", conpubs) dtrAuthor = cmdselect.ExecuteReader() dtrlstAuthor.DataSource = dtrAuthor dtrlstAuthor.DataBind() dtrAuthor.Close()
Protected Sub dtrlstAuthor_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.ItemCommand dtrlstAuthor.SelectedIndex = e.Item.ItemIndex BindDatalist() End Sub End Class
Sample I/O:
----------------------------------------------------------------------------------------------------------------------------------------
AIM: Write a Program to display how data bind using dropdown list.
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" runat="server" Style="z-index: 100; left: 200px; position: absolute; top: 40px">
</asp:DropDownList> <asp:Button ID="Button1" runat="server" Style="z-index: 101; left: 384px; position: absolute; top: 40px" Text="Button" Width="96px" /> <asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 240px; position: absolute; top: 112px" Text="Label" Width="104px"></asp:Label>
</html>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Label1.Text = "you pick" & DropDownList1.SelectedValue End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim conpubs As SqlConnection Dim cmdselect As SqlCommand Dim dtrAuthor As SqlDataReader conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("select Au_fname from Author", conpubs) conpubs.Open() dtrAuthor = cmdselect.ExecuteReader() DropDownList1.DataSource = dtrAuthor DropDownList1.DataTextField = "Au_fname" DropDownList1.DataBind() dtrAuthor.Close() conpubs.Close() End If End Sub End Class
Sample I/O:
------------------------------ ------------------------------------------------------------------------------------------------------------
AIM: Write a Program to insert the data in to database using Execute-Non Query.
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 160px; position: absolute; top: 32px" Text="Au_fname"></asp:Label> <asp:TextBox ID="txtfname" runat="server" Style="z-index: 101; left: 112px; position: absolute; top: 72px"></asp:TextBox> <asp:Label ID="Label2" runat="server" Style="z-index: 102; left: 168px; position: absolute; top: 136px" Text="Au_lname"></asp:Label> <asp:TextBox ID="txtlname" runat="server" Style="z-index: 103; left: 128px; position: absolute; top: 176px"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 104; left: 160px; position: absolute; top: 240px" Text="Add" Width="56px" /> </form> </body></html>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conpubs As SqlConnection Dim strInsert As String Dim cmdInsert As SqlCommand conpubs = New SqlConnection(constr) strInsert = "Insert Author(Au_fname,Au_lname)values(@Au_fname,@Au_lname)" cmdInsert = New SqlCommand(strInsert, conpubs) cmdInsert.Parameters.Add("@Au_fname", txtfname.Text) cmdInsert.Parameters.Add("@Au_lname", txtlname.Text) conpubs.Open() cmdInsert.ExecuteNonQuery() conpubs.Close() Response.Write(New Row inserted) End Sub End Class
Sample I/O:
------------------------------------------------------------------------------------------------------------------------------------------
AIM: Write a Program to delete the data in to database using Execute non-query.
Design:
Remove
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Style="z-index: 100; left: 272px; position: absolute; top: 64px" Text="Au_fname"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 101; left: 232px; position: absolute; top: 128px"></asp:TextBox> <asp:Label ID="Label2" runat="server" Style="z-index: 102; left: 272px; position: absolute; top: 176px" Text="Au_lname"></asp:Label> <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 103; left: 224px; position: absolute; top: 216px"></asp:TextBox> <asp:Button ID="Button1" runat="server" Style="z-index: 104; left: 272px; position: absolute; top: 264px" Text="Remove" /> </div> </form> </body> </html>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("RajeevConnectionString1").ConnectionSt ring Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conpubs As SqlConnection Dim strdelete As String Dim cmddelete As SqlCommand conpubs = New SqlConnection(constr) strdelete = "delete from Author where Au_fname=@Au_fname" cmddelete = New SqlCommand(strdelete, conpubs) cmddelete.Parameters.Add("@Au_fname", TextBox1.Text) conpubs.Open() cmddelete.ExecuteNonQuery() Response.Write("Row delete") conpubs.Close() End Sub End Class
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="dlstAuthor" runat="server" Style="z-index: 16; left: 0px; position: absolute; top: 0px"> <ItemTemplate> <%#Container.DataItem("Au_fname")%> </ItemTemplate> </asp:DataList>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conpubs As SqlConnection Dim cmdselect As SqlCommand Dim dtrAuthor As SqlDataReader conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("Select Au_fname from Author", conpubs) conpubs.Open() dtrAuthor = cmdselect.ExecuteReader() dlstAuthor.DataSource = dtrAuthor dlstAuthor.DataBind() dtrAuthor.Close() conpubs.Close() End Sub End Class
Sample I/O:
------------------------------------------------------------------------------------------------------------------------------------------
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="dtrlstAuthor" runat="server" Style="z-index: 16; left: 40px; position: absolute; top: 40px"> <HeaderTemplate > <h2> Author Phone Number</h2> </HeaderTemplate> <ItemTemplate> <tabel> <tr> <td align="right"> Au_name: </td> <td> <%# container.DataItem ("Au_name")%> </td> </tr> <tr> <td align ="right" > Au_lname:
</td> <td> <%# Container.DataItem("Au_lname") %> </td> </tr> <tr> <td align="right">Phone: </td> <td> <%#Container.DataItem("phone")%> </td> </tr> </tabel> </ItemTemplate> <SelectedItemTemplate > <hr> </SelectedItemTemplate> <EditItemStyle BackColor ="Red" /> <ItemStyle BackColor ="White" /> </asp:DataList>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conpubs As SqlConnection Dim cmdselect As SqlCommand Dim dtrAuthor As SqlDataReader conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("Select * from Author", conpubs) conpubs.Open() dtrAuthor = cmdselect.ExecuteReader() dtrlstAuthor.DataSource = dtrAuthor dtrlstAuthor.DataBind() dtrAuthor.Close() conpubs.Close() End Sub End Class
Sample I/O:
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="datagrd" runat="server" Style="z-index: 100; left: 16px; position: absolute; top: 8px" AutoGenerateColumns="False"> <Columns > <asp:BoundField DataField ="Au_fname" /> <asp:BoundField DataField ="Au_lname" /> </Columns> </asp:GridView>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("RajeevConnectionString1").ConnectionSt ring Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conpubs As SqlConnection Dim cmdselect As SqlCommand conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("select * from Author", conpubs) conpubs.Open() datagrd.DataSource = cmdselect.ExecuteReader() datagrd.DataBind() conpubs.Close() End Sub
Sample I/O:
-----------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to bind data using template column in data grid.
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="datagrd" runat="server" AutoGenerateColumns="False" Style="z-index: 100; left: 160px; position: absolute; top: 8px"> <Columns > <asp:BoundField DataField ="Au_fname" /> <asp:TemplateField > <ItemTemplate > <table > <tr> <td>phone:</td> <td><%# Container.DataItem("phone") %> </td> </tr> <tr> <td>city:</td> <td><%# container.DataItem ("city") </table> %></td></tr>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DAtabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conpubs As SqlConnection Dim cmdselect As SqlCommand conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("select * from Author", conpubs) conpubs.Open() datagrd.DataSource = cmdselect.ExecuteReader() datagrd.DataBind() conpubs.Close() End Sub End Class
Sample I/O:
----------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to bind data using Hyperlink column in data grid.
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="datagrdlnk" runat="server" AutoGenerateColumns="False" Style="z-index: 100; left: 224px; position: absolute; top: 24px" EnableViewState="False" ShowHeader="False"> <Columns > <asp:HyperLinkField DataNavigateUrlFields ="link_url" DataTextField ="link_title"/> </Columns> </asp:GridView> </div> </form> </body> </html>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim conpubs As SqlConnection Dim cmdselect As SqlCommand conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("select * from conpubs.Open() datagrdlnk.DataSource = cmdselect.ExecuteReader() datagrdlnk.DataBind() conpubs.Close() End Sub End Class Author", conpubs)
Sample I/O:
------------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to bind data using button column in data grid. Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px" AutoGenerateColumns="False"> <Columns > <asp:BoundField HeaderText ="Au_fname" DataField ="Au_fname" /> <asp:ButtonField CommandName ="select" Text ="select" /> <asp:ButtonField CommandName ="unselect" Text ="unselect" /> </Columns> </asp:GridView>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim conpubs As SqlConnection Dim cmdselect As SqlCommand conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("select * from Author", conpubs) conpubs.Open() GridView1.DataSource = cmdselect.ExecuteReader() GridView1.DataBind() conpubs.Close() End If End Sub Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand If e.CommandName = "select" Then GridView1.SelectedRowStyle.BackColor = Drawing.Color.Green Else GridView1.SelectedRowStyle.BackColor = Drawing.Color.White End If End Sub End Class
Design:
Source:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList ID="dtrlstAuthor" runat="server" Style="z-index: 100; left: 8px; position: absolute; top: 112px" RepeatColumns="3" RepeatDirection="Horizontal" CellPadding="10" GridLines="Both"> <ItemTemplate > <%# Container.DataItem("Au_fname") %> <br> <asp:LinkButton ID="linkbutton1" Text="Edit" commandname="Edit" Runat="server" /> <asp:LinkButton ID="linkbutton2" Text="Delete" commandname="Delete" Runat="server" /> <asp:LinkButton ID ="linkbutton3" Text="Update" commandname="Update"
Runat="server" /> <asp:LinkButton ID ="linkbutton4" Text="Cancel" commandname="Cancel" Runat="server" /> <asp:LinkButton ID ="linkbutton5" Text="Item" commandname="Item" Runat="server" /> </ItemTemplate> </asp:DataList>
</div> <asp:Label ID="lb1Message" runat="server" Style="z-index: 101; left: 48px; position: absolute; top: 32px"></asp:Label> </form> </body> </html>
Code:
Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("RajeevConnectionString1").ConnectionSt ring
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim conpubs As SqlConnection Dim cmdselect As SqlCommand Dim dtrAuthor As SqlDataReader conpubs = New SqlConnection(constr) cmdselect = New SqlCommand("Select * from Author", conpubs) conpubs.Open() dtrAuthor = cmdselect.ExecuteReader() dtrlstAuthor.DataSource = dtrAuthor dtrlstAuthor.DataBind() dtrAuthor.Close() conpubs.Close() End If End Sub Protected Sub dtrlstAuthor_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.CancelCommand lb1Message.Text = "<li> Cancel Item!" End Sub Protected Sub dtrlstAuthor_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.DeleteCommand lb1Message.Text = "<li> Delete Item!" End Sub Protected Sub dtrlstAuthor_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.EditCommand lb1Message.Text &= "<li> Edit item!" End Sub
Protected Sub dtrlstAuthor_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.ItemCommand lb1Message.Text = "<li> Item command!" End Sub Protected Sub dtrlstAuthor_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dtrlstAuthor.UpdateCommand lb1Message.Text = "<li> Update Item!" End Sub End Class
Sample I/O:
-------------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program to implement paging concept data grid and dataset.
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 32px; position: absolute; top: 24px" AllowPaging="True" PageSize="2"> </asp:GridView>
Code:
Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page Dim constr As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").Connection String Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Binddatagrid() End If End Sub Sub Binddatagrid() Dim conpubs As SqlConnection Dim dtrtitle As SqlDataAdapter Dim datset As DataSet conpubs = New SqlConnection(constr) dtrtitle = New SqlDataAdapter("select * from Author", conpubs) datset = New DataSet dtrtitle.Fill(datset) GridView1.DataSource = datset GridView1.DataBind() End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.PageIndexChanged End Sub Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging GridView1.PageIndex = e.NewPageIndex Binddatagrid() End Sub Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Sample I/O:
-------------------------------------------------------------------------------------------------------------------------------------------AIM: Write a Program create an own table and bind data using data grid.
Design:
Source:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" Style="z-index: 100; left: 0px; position: absolute; top: 0px"> </asp:GridView>
Code:
Imports System.Data Partial Class _Default Inherits System.Web.UI.Page Function CreateDatasource() As ICollection Dim dt As New DataTable() Dim dr As DataRow dt.Columns.Add(New DataColumn("integervalue", GetType(Int32))) dt.Columns.Add(New DataColumn("stringvalue", GetType(String))) dt.Columns.Add(New DataColumn("currencyvalue", GetType(Double))) Dim i As Integer For i = 0 To 8 dr = dt.NewRow() dr(0) = i dr(1) = "item" + i.ToString dr(2) = 1.23 * (i + 1) dt.Rows.Add(dr) Next i Dim dv As New DataView(dt) Return dv End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then GridView1.DataSource = CreateDatasource() GridView1.DataBind() End If End Sub End Class
Sample I/O: