Latihan Modul Program VB Net 2 (Asp)
Latihan Modul Program VB Net 2 (Asp)
PROGRAM VB .NET 2
(ASP)
1
LATIHAN 1
1. Open program Microsoft Visual Studio 2008 dan click File ➔ New ➔ Project
2. Pilih Visual Basic ➔ Web ➔ASP.NET Web Application lalu ketik Latihan1
pada colom Name, lalu click Browse untuk memilih lokasi Projecy lalu click
tombol OK
2
3. Tampilan awal setelah project selesai dibuat
4. Ketikan coding dibawah ini untuk desain web yang akan ditampilkan
</form>
</body>
</html>
5. Untuk menjalan web aplikasi tersebut, click kanan pada file Default.aspx dan
click Set As Start Page
4
LATIHAN 2
2. Pilih Web ➔ Web Form dan ketikan WebKedua.aspx pada kolom Name
5
3. Struktur project Ketika sudah ditambahkan 2 WebForm baru seperti diatas
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr style="text-align:center;" >
<td colspan="6" >DATA MAHASISWA</td>
</tr>
<tr>
<td colspan="6" > </td>
</tr>
<tr>
<td>NIM</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtNim" runat="server" Width="100px"
></asp:TextBox>
</td>
</tr>
6
<tr>
<td>NAMA</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtNama" runat="server" Width="480px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>TGL LAHIR</td>
<td>:</td>
<td>
<cc1:DatePicker ID="dtTglLahir" runat="server"
Width="80px" PaneWidth="150px" EnableViewState="true">
<PaneTableStyle BorderColor="#707070"
BorderWidth="1px" BorderStyle="Solid" />
<PaneHeaderStyle BackColor="#0099FF" />
<TitleStyle ForeColor="White" Font-Bold="true" />
<NextPrevMonthStyle ForeColor="White" Font-
Bold="true" />
<NextPrevYearStyle ForeColor="#E0E0E0" Font-
Bold="true" />
<DayHeaderStyle BackColor="#E8E8E8" />
<TodayStyle BackColor="#FFFFCC"
ForeColor="#000000" Font-Underline="false" BorderColor="#FFCC99"/>
<AlternateMonthStyle BackColor="#F0F0F0"
ForeColor="#707070" Font-Underline="false"/>
<MonthStyle BackColor="" ForeColor="#000000" Font-
Underline="false"/>
</cc1:DatePicker>
</td>
<td style="width:50px;" ></td>
<td>TEMPAT LAHIR</td>
<td>
<asp:TextBox ID="txtTempatLahir" runat="server"
Width="185px" ></asp:TextBox>
</td>
</tr>
<tr>
<td>ALAMAT</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtALamat" runat="server" Width="480px"
></asp:TextBox>
</td>
</tr>
7
<tr>
<td>JENIS KELAMIN</td>
<td>:</td>
<td >
<asp:RadioButtonList ID="optJenisKelamin" runat="server"
RepeatDirection="Horizontal" >
<asp:ListItem Text="Pria" Value="P"></asp:ListItem>
<asp:ListItem Text="Wanita" Value="W"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td style="width:50px;" ></td>
<td>AGAMA</td>
<td>
<asp:DropDownList ID="ddlAgama" runat="server"
Width="190px">
<asp:ListItem Text="ISLAM" Value="I"></asp:ListItem>
<asp:ListItem Text="KRISTEN"
Value="K"></asp:ListItem>
<asp:ListItem Text="KATOLIK"
Value="T"></asp:ListItem>
<asp:ListItem Text="HINDU" Value="H"></asp:ListItem>
<asp:ListItem Text="BUDHA" Value="B"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>HOBI</td>
<td>:</td>
<td colspan="4" >
<asp:CheckBox ID="chk1" runat="server" Text="OLAH
RAGA" />
<asp:CheckBox ID="chk2" runat="server"
Text="TRAVELING" />
<asp:CheckBox ID="chk3" runat="server"
Text="MEMBACA" />
<asp:CheckBox ID="chk4" runat="server" Text="LAINNYA" />
</td>
</tr>
<tr>
<td colspan="6" > </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="4" >
<asp:Button ID="btnSave" runat="server" Text="SAVE" />
8
<asp:Button ID="btnClear" runat="server" Text="CLEAR" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
b. Code Behind Click Menu View ➔ Code (atau tekan tombol F7)
Public Class WebKedua
Inherits System.Web.UI.Page
9
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles
btnSave.Click
Try
Session.Item("NIM") = txtNim.Text
Session.Item("NAMA") = txtNama.Text
Session.Item("ALAMAT") = txtALamat.Text
Session.Item("TEMPATLHR") = txtTempatLahir.Text
Session.Item("TGLLAHIR") = dtTglLahir.SelectedDate
Session.Item("AGAMA") = ddlAgama.SelectedValue
Session.Item("JNSKELAMIN") = optJenisKelamin.SelectedIndex
If chk1.Checked Then
Session.Item("HOBI1") = 1
Else
Session.Item("HOBI1") = 0
End If
If chk2.Checked Then
Session.Item("HOBI2") = 1
Else
Session.Item("HOBI2") = 0
End If
If chk3.Checked Then
Session.Item("HOBI3") = 1
Else
Session.Item("HOBI3") = 0
End If
If chk4.Checked Then
Session.Item("HOBI4") = 1
Else
Session.Item("HOBI4") = 0
End If
Response.Redirect("WebTampil.aspx", False)
Catch ex As Exception
End Try
End Sub
End Class
<html xmlns="http://www.w3.org/1999/xhtml">
10
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr style="text-align:center;" >
<td colspan="6" >VIEW MAHASISWA</td>
</tr>
<tr>
<td colspan="6" > </td>
</tr>
<tr>
<td>NIM</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtNim" runat="server" Width="100px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>NAMA</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtNama" runat="server" Width="480px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>TGL LAHIR</td>
<td>:</td>
<td>
<cc1:DatePicker ID="dtTglLahir" runat="server"
Width="80px" PaneWidth="150px" EnableViewState="true">
<PaneTableStyle BorderColor="#707070"
BorderWidth="1px" BorderStyle="Solid" />
<PaneHeaderStyle BackColor="#0099FF" />
<TitleStyle ForeColor="White" Font-Bold="true" />
<NextPrevMonthStyle ForeColor="White" Font-
Bold="true" />
<NextPrevYearStyle ForeColor="#E0E0E0" Font-
Bold="true" />
<DayHeaderStyle BackColor="#E8E8E8" />
<TodayStyle BackColor="#FFFFCC"
ForeColor="#000000" Font-Underline="false" BorderColor="#FFCC99"/>
11
<AlternateMonthStyle BackColor="#F0F0F0"
ForeColor="#707070" Font-Underline="false"/>
<MonthStyle BackColor="" ForeColor="#000000" Font-
Underline="false"/>
</cc1:DatePicker>
</td>
<td style="width:50px;" ></td>
<td>TEMPAT LAHIR</td>
<td>
<asp:TextBox ID="txtTempatLahir" runat="server"
Width="185px" ></asp:TextBox>
</td>
</tr>
<tr>
<td>ALAMAT</td>
<td>:</td>
<td colspan="4" >
<asp:TextBox ID="txtALamat" runat="server" Width="480px"
></asp:TextBox>
</td>
</tr>
<tr>
<td>JENIS KELAMIN</td>
<td>:</td>
<td >
<asp:RadioButtonList ID="optJenisKelamin" runat="server"
RepeatDirection="Horizontal" >
<asp:ListItem Text="Pria" Value="P"></asp:ListItem>
<asp:ListItem Text="Wanita" Value="W"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td style="width:50px;" ></td>
<td>AGAMA</td>
<td>
<asp:DropDownList ID="ddlAgama" runat="server"
Width="190px">
<asp:ListItem Text="ISLAM" Value="I"></asp:ListItem>
<asp:ListItem Text="KRISTEN"
Value="K"></asp:ListItem>
<asp:ListItem Text="KATOLIK"
Value="T"></asp:ListItem>
<asp:ListItem Text="HINDU" Value="H"></asp:ListItem>
<asp:ListItem Text="BUDHA" Value="B"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
12
<tr>
<td>HOBI</td>
<td>:</td>
<td colspan="4" >
<asp:CheckBox ID="chk1" runat="server" Text="OLAH
RAGA" />
<asp:CheckBox ID="chk2" runat="server"
Text="TRAVELING" />
<asp:CheckBox ID="chk3" runat="server"
Text="MEMBACA" />
<asp:CheckBox ID="chk4" runat="server" Text="LAINNYA" />
</td>
</tr>
<tr>
<td colspan="6" > </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="4" >
<asp:Button ID="btnBack" runat="server" Text="BACK" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
b. Code Behind
Public Class WebTampil
Inherits System.Web.UI.Page
13
Else
chk1.Checked = False
End If
If Session.Item("HOBI2") = 1 Then
chk2.Checked = True
Else
chk2.Checked = False
End If
If Session.Item("HOBI3") = 1 Then
chk3.Checked = True
Else
chk3.Checked = False
End If
If Session.Item("HOBI4") = 1 Then
chk4.Checked = True
Else
chk4.Checked = False
End If
End If
Catch ex As Exception
End Try
End Sub
6. Untuk menjalan WebKedua tersebut, click kanan pada file WebKedua.aspx dan
click Set As Start Page
14
7. Running program
a. WebKedua.aspx ➔ Click button SAVE or CLEAR
15
LATIHAN 3
1. Buka project Latihan1 dan tambahkan 1 WebForm baru dengan nama
WebKetiga.aspx
16
.StyleMenu .HeaderBar {
font: bold 13px Verdana;
color: white;
background: #606060 url(arrowstop.gif) no-repeat 8px 6px;
margin-bottom: 0;
text-transform: uppercase;
padding: 7px 0 7px 31px;
}
.StyleMenu ul
{
list-style-type: none;
margin: 0;
padding: 0;
margin-bottom: 0;
}
.StyleMenu ul li
{
padding-bottom: 2px;
}
.StyleMenu ul li a
{
font: normal 12px Arial;
color: black;
background :silver;
display: block;
padding: 5px 0;
line-height: 17px;
padding-left: 8px;
text-decoration: none;
}
.StyleMenu ul li a:visited
{
color: black;
}
.StyleMenu ul li a:hover
{
color :white ;
background: black;
}
17
b. Code HTML
<%@ Page Language="vb" AutoEventWireup="false"
CodeBehind="WebKetiga.aspx.vb" Inherits="Latihan1.WebKetiga" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>SISTEM AKADEMIK</title>
<script type="text/javascript">
function ValidateNIM() {
var v = document.getElementById("<%=txtNim.ClientID%>");
var cnim = v.value;
v.setAttribute('BackColor', 'red');
if (cnim == "") {
return true;
}
if (cnim.length != 10) {
v.style.backgroundColor = 'red';
document.getElementById('<%=lblErr1.ClientID%>').innerHTML
= 'NIM harus 10 digits';
v.focus();
return false;
}
v.style.backgroundColor = 'white';
document.getElementById('<%=lblErr1.ClientID%>').innerHTML =
'';
return true;
}
function OnlyNumericEntry() {
if ((event.keyCode < 48 || event.keyCode > 57)) {
event.returnValue = false;
}
}
</script>
<style type="text/css">
.style7
{
text-align: center;
}
.style9
{
font-family: "Courier New";
font-size: small;
color: #FFFFFF;
18
}
.newStyle1
{
font-family: "Courier New", Courier, monospace;
font-size: small;
}
.style12
{
font-size: x-large;
color: #333333;
font-weight: bold;
}
.style13
{
font-size: small;
font-style: italic;
}
.style14
{
text-align: justify;
}
.style15
{
font-size: small;
font-style: italic;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
}
</style>
<link href="menustyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div style="width:800px; height:610px; margin:auto;
background:#999999; padding-top:10px; border:1px; " >
<div style="width:780px; height:125px; margin:auto;
background:white; padding-top:5px; " >
<div style ="width:770px; height:110px; background:gray;
margin:auto; padding-top:0px; padding-bottom:0px;">
<img src="logoip.jpg" width="770" height ="120" alt =""/>
</div>
</div>
<div style ="width:780px; height:415px; margin:auto;
background:#999999; margin-top:5px; padding-bottom :5px; " >
<div style="width:230px; height:415px; float:left;
background:white; " >
19
<div style ="width:215px; height:20px; background:#333333;
margin:auto; padding-left:5px; padding-top:5px; padding-bottom:5px;
margin-top:5px;">
<asp:TextBox ID ="txtFind" runat ="server" Width ="160px"
BorderStyle ="Solid" ></asp:TextBox>
<asp:Button ID="btnFind" Text ="Find" runat ="server"
Width="40px" class="btn "
onmouseover="this.style.color='Black';
this.style.backgroundColor='White';
this.style.borderColor='Black';"
onmouseout="this.style.color='White';
this.style.backgroundColor='#333333';
this.style.borderColor='Gray';" />
</div>
<div style =" width:215px; height:357px; background:#333333;
margin:auto; padding-left:5px; padding-bottom:5px; margin-top:5px; ">
<div class="StyleMenu">
<h3 class="HeaderBar">MAIN MENU</h3>
<ul>
<li><a href="">HOME</a></li>
<li><a href="" >OLAH MAHASISWA</a></li>
<li><a href="" >OLAH DOSEN</a></li>
<li><a href="" >OLAH MATA KULIAH</a></li>
<li><a href="" >OLAH DATA KRS</a></li>
<li><a href="" >OLAH DATA KHS</a></li>
<li><a href="" >OLAH LAPORAN</a></li>
</ul>
</div>
</div>
</div>
<div style ="width:545px; height:415px; float:right;
background:white;" >
<div style =" width:515px; height:20px; background:silver;
margin:auto; padding-right :10px; padding-left:10px; padding-top:5px;
padding-bottom:5px; margin-top:5px;">
<table align="center" >
<tr align="center" valign="middle">
<td align="center" valign="middle">OLAH DATA
MAHASISWA</td>
</tr>
</table>
</div>
<div style =" width:525px; height:195px; background:silver;
margin:auto; padding-right :10px; padding-left:0px; padding-top:5px;
padding-bottom:5px; margin-top:5px; ">
<table align="center" >
20
<tr>
<td width="150px">NIM</td>
<td>:</td>
<td>
<asp:TextBox ID="txtNim" runat="server"
Width="159px" onkeypress="OnlyNumericEntry()" OnBlur="return
ValidateNIM()"></asp:TextBox>
<asp:Label ID="lblErr1" Text="" ForeColor="Red"
runat="server"></asp:Label>
</td>
</tr>
<tr>
<td width="150px">NAMA</td>
<td>:</td>
<td>
<asp:TextBox ID="txtNama" runat="server"
Width="159px"></asp:TextBox>
</td>
</tr>
<tr>
<td width="150px">ALAMAT</td>
<td>:</td>
<td>
<asp:TextBox ID="txtAlamat" TextMode="MultiLine"
runat="server" Width="159px"></asp:TextBox>
</td>
</tr>
<tr>
<td width="150px">JURUSAN</td>
<td>:</td>
<td>
<asp:TextBox ID="txtJurusan" runat="server"
Width="159px"></asp:TextBox>
</td>
</tr>
<tr>
<td width="150px">NO. TELPHONE</td>
<td>:</td>
<td>
<asp:TextBox ID="txtTelpon" runat="server"
Width="159px"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
21
<td> </td>
</tr>
</table>
<table align="center" >
<tr align="center" >
<td>
<asp:Button ID="btnSave" Width="80px"
runat="server" Text="Save" />
</td>
<td>
<asp:Button ID="btnUpdate" Width="80px"
runat="server" Text="Update" />
</td>
<td>
<asp:Button ID="btnDelete" Width="80px"
runat="server" Text="Delete" />
</td>
<td>
<asp:Button ID="btnReset" Width="80px"
runat="server" Text="Reset" />
</td>
</tr>
</table>
</div>
<div style =" width:525px; height:150px; background:silver;
margin:auto; padding-right :10px; padding-left:0px; padding-top:5px;
padding-bottom:5px; margin-top:5px; overflow:auto ; ">
<asp:GridView ID ="grdList" runat ="server"
AutoGenerateColumns ="false"
ShowFooter ="false" Width ="600px" >
<Columns >
<asp:CommandField ControlStyle-ForeColor="Blue"
HeaderText ="Select" ShowHeader="true" ShowSelectButton ="true" >
<ControlStyle ForeColor ="Blue" />
</asp:CommandField>
<asp:BoundField DataField ="NIM_MHS" HeaderText
="NIM" ItemStyle-Width ="40px" >
<HeaderStyle Wrap ="false" />
<ItemStyle Wrap ="false" />
</asp:BoundField >
<asp:BoundField DataField ="NM_MHS" HeaderText
="NAMA" ItemStyle-Width ="150px" >
<HeaderStyle Wrap ="false" />
<ItemStyle Wrap ="false" />
</asp:BoundField >
22
<asp:BoundField DataField ="ALAMAT_MHS"
HeaderText ="ALAMAT" ItemStyle-Width ="200px" >
<HeaderStyle Wrap ="false" />
<ItemStyle Wrap ="false" />
</asp:BoundField >
<asp:BoundField DataField ="JUR_MHS" HeaderText
="JURUSAN" ItemStyle-Width ="100px" >
<HeaderStyle Wrap ="false" />
<ItemStyle Wrap ="false" />
</asp:BoundField >
<asp:BoundField DataField ="TELP_MHS"
HeaderText ="TELPON" ItemStyle-Width ="80px" >
<HeaderStyle Wrap ="false" />
<ItemStyle Wrap ="false" />
</asp:BoundField >
</Columns>
</asp:GridView>
</div>
</div>
</div>
<div style="width:780px; height:40px; margin:auto;
background:white; padding-top:5px;" class="style7" >
<div style ="width:770px; height:30px; background:#333333;
margin:auto; padding-bottom:5px;" >
<span class="style9">Copyrights by UNIPI -
TANGERANG</span><br class="style9" />
<span class="style9"><span class="style9">© 2023 All
Rights Reserved</span></span><span class="style9"> </span>
</div>
</div>
</div>
</form>
</body>
</html>
23
4. Running program aplikasi
24