Vous êtes sur la page 1sur 21

Contoh Form Pnedaftaran

<%@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
msgLabel.Text = "Nama : " + txtNama.Text + "<br/>";
if (txtJkel.SelectedItem != null)
{
msgLabel.Text += "Jenis Kelamin : " + txtJkel.SelectedItem.Value + "<br/>";
}

else
{
msgLabel.Text += "Jenis Kelamin : <br/>";
}
msgLabel.Text += "Agama : " + txtAgama.Text + "<br/>"; string materi = "";
foreach (ListItem item in txtMateri.Items)
{
if (item.Selected)
materi += item.Text + ",";
}
if (materi.Length > 0)
{
msgLabel.Text += "Materi Kursus : " + materi;
}
else
{
msgLabel.Text += "Materi Kursus : ";
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
}
protected void txtAgama_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button1_Click2(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 149px;
}
.style4
{
width: 443px;
}
.style5
{
width: 80px;
}
.style6
{
width: 149px;
height: 23px;
}
.style7
{

width: 443px;
height: 23px;
}
.style8
{
width: 90px;
}
.style9
{
width: 149px;
height: 34px;
}
.style10
{
width: 443px;
height: 34px;
}
</style>
</head>
<body>
<p>
&nbsp;</p>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="txtNama" runat="server" Text="Nama"></asp:Label>
</td>
<td class="style4">
<asp:TextBox ID="TextBox1" runat="server" Width="194px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="txtjeniskelamin" runat="server" Text="Jenis
Kelamin"></asp:Label>
</td>
<td class="style4">
<table class="style1">
<tr>
<td class="style8">
<asp:RadioButtonList ID="txtJkel" runat="server">
<asp:ListItem Value="1">Laki Laki</asp:ListItem>
<asp:ListItem Value="2">perempuan</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
&nbsp;</td>
</tr>
</table>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="txtlabel" runat="server" Text="Agama"></asp:Label>
</td>
<td class="style4">
<table class="style1">
<tr>
<td class="style5">
<asp:DropDownList ID="txtAgama" runat="server"

onselectedindexchanged="txtAgama_SelectedIndexChanged">
<asp:ListItem Value="1">Islam</asp:ListItem>
<asp:ListItem Value="2">Katolik</asp:ListItem>
<asp:ListItem Value="3">Protestan</asp:ListItem>
<asp:ListItem Value="4">Hindu</asp:ListItem>
<asp:ListItem Value="5">Budha</asp:ListItem>
<asp:ListItem Value="6">Kong Hu Cu</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="txtMaterikursus" runat="server" Text="Materi
Kursus"></asp:Label>
</td>
<td class="style4">
<asp:CheckBoxList ID="txtMateri" runat="server">
<asp:ListItem>Ms Office</asp:ListItem>
<asp:ListItem Value="2">Corel Drow</asp:ListItem>
<asp:ListItem Value="3">Auto CAD</asp:ListItem>
<asp:ListItem Value="4">ASP NET</asp:ListItem>
<asp:ListItem Value="5">PHP</asp:ListItem>
</asp:CheckBoxList>
</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
<td class="style7">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
<td class="style7">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
<td class="style7">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
</tr>
<tr>
<td class="style9">
<asp:Button ID="Sumbit" runat="server" Text="Submit" onclick="Button1_Click"
style="height: 26px" />
&nbsp;<asp:Button ID="Button1" runat="server" Text="Clear"
onclick="Button1_Click2" />
</td>
<td class="style10">
&nbsp;</td>
</tr>
<tr>

<td class="style6">
</td>
<td class="style7">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
</td>
<td class="style7">
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="msgLabel" runat="server" Text="Keterangan"></asp:Label>
</td>
<td class="style4">
&nbsp;</td>
</tr>
<tr>
<td class="style2">
&nbsp;</td>
<td class="style4">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
</td>
<td class="style7">
</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
<td class="style7">
&nbsp;</td>
</tr>
<tr>
<td class="style6">
&nbsp;</td>
<td class="style7">
&nbsp;</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>

Program Discount

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

protected void Button2_Click(object sender, EventArgs e)


{
txtHarga.Text = null;
txtDiskon.Text = null;
txtBDiskon.Text = "Rp";
txtTotal.Text = "Rp";
}
protected void Button1_Click(object sender, EventArgs e)
{
double harga, diskon, total_diskon, bayar;
harga = Convert.ToDouble(txtHarga.Text);
diskon = Convert.ToDouble(txtDiskon.Text);
total_diskon = harga * diskon / 100 ;
bayar = harga - total_diskon;
txtBDiskon.Text = Convert.ToString(total_diskon);
txtTotal.Text = Convert.ToString(bayar);
}
protected void txtBDiskon_TextChanged(object sender, EventArgs e)
{
txtBDiskon.Text = ("C");

}
protected void txtTotal_TextChanged(object sender, EventArgs e)
{
}
protected void txtHarga_TextChanged(object sender, EventArgs e)
{
txtHarga.Text = string.Format("{0:n0}", double.Parse(txtHarga.Text));
}
protected void txtDiskon_TextChanged(object sender, EventArgs e)
{
}
protected void Page_PreLoad(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 99%;
}
.style9
{
font-weight: bold;
}
.style10
{
width: 139px;
}
.style11
{
width: 7px;
font-weight: 700;
}
.style12
{
height: 26px;
}
.style13
{
width: 7px;
font-weight: 700;
height: 26px;
}
.style14
{
height: 26px;
}
.style15
{
width: 187px;
}
.style16
{
height: 26px;
width: 187px;
}
.style17
{
text-align: left;
}
.style19
{
width: 139px;
height: 39px;
}
.style20
{
width: 7px;
font-weight: 700;
height: 39px;
}
.style21
{

width: 187px;
height: 39px;
}
.style22
{
height: 39px;
}
.style23
{
text-align: right;
}
.style24
{
height: 47px;
font-size: xx-large;
}
.style25
{
height: 12px;
}
.style26
{
width: 7px;
font-weight: 700;
height: 12px;
}
.style27
{
height: 12px;
width: 187px;
}
.style32
{
text-align: left;
width: 191px;
}
.style33
{
text-align: right;
width: 191px;
}
.style34
{
height: 12px;
width: 191px;
}
.style35
{
height: 26px;
width: 191px;
}
.style36
{
width: 191px;
}
.style37
{
width: 191px;
height: 39px;
}
</style>
</head>
<body>

<form id="form1" runat="server">


<div>
<table class="style1">
<tr>
<td class="style24" colspan="4">
<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
***Aplikasi
Diskon***</strong></td>
<td class="style24">
&nbsp;</td>
</tr>
<tr>
<td class="style25">
</td>
<td class="style26">
</td>
<td class="style27">
</td>
<td class="style34">
</td>
<td class="style25">
&nbsp;</td>
</tr>
<tr>
<td class="style12">
<asp:Label ID="Label1" runat="server"
style="font-weight: 700; font-size: medium" Text="Harga
Barang"></asp:Label>
</td>
<td class="style13">
:</td>
<td class="style16">
<asp:TextBox ID="txtHarga" runat="server" BackColor="#3399FF"
Width="185px"
ontextchanged="txtHarga_TextChanged"></asp:TextBox>
</td>
<td class="style35">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtHarga" ErrorMessage="Masukkan Harga !!!!"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td class="style14">
&nbsp;</td>
</tr>
<tr>
<td class="style10">
<asp:Label ID="Label2" runat="server" CssClass="style9" Text="Diskon
(%)"></asp:Label>
</td>
<td class="style11">
:</td>
<td class="style15">
<asp:TextBox ID="txtDiskon" runat="server" BackColor="#3399FF"
Width="185px"
ontextchanged="txtDiskon_TextChanged"></asp:TextBox>
</td>
<td class="style36">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtDiskon" ErrorMessage="Masukkan Jumlah Diskon !!!!"
ForeColor="Red"></asp:RequiredFieldValidator>
</td>
<td>

&nbsp;</td>
</tr>
<tr>
<td class="style19">
</td>
<td class="style20">
</td>
<td class="style21">
<asp:Button ID="Button1" runat="server" Text="Hitung" BackColor="#FF2222"
onclick="Button1_Click" Width="80px" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Clear"
BackColor="#FF2222" Width="80px" />
</td>
<td class="style37">
</td>
<td class="style22">
&nbsp;</td>
</tr>
<tr>
<td class="style10">
<asp:Label ID="Label3" runat="server" CssClass="style9"
Text="Besar Diskon (Rp)"></asp:Label>
</td>
<td class="style11">
:</td>
<td class="style15">
<asp:TextBox ID="txtBDiskon" runat="server" BackColor="#FF8000"
Width="185px"
ontextchanged="txtBDiskon_TextChanged" AccessKey="<%$ RouteValue:Rp
%>"></asp:TextBox>
</td>
<td class="style36">
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td class="style12">
<asp:Label ID="Label4" runat="server" CssClass="style9" Text="Total
(Rp)"></asp:Label>
</td>
<td class="style13">
:</td>
<td class="style16">
<asp:TextBox ID="txtTotal" runat="server" BackColor="#FF8000"
Width="185px"
ontextchanged="txtTotal_TextChanged"></asp:TextBox>
</td>
<td class="style35">
</td>
<td class="style14">
&nbsp;</td>
</tr>
<tr>
<td class="style10">
&nbsp;</td>
<td class="style11">
&nbsp;</td>
<td class="style15">
&nbsp;</td>
<td class="style32">
&nbsp;</td>

<td class="style17">
&nbsp;</td>
</tr>
<tr>
<td class="style10">
&nbsp;</td>
<td class="style11">
&nbsp;</td>
<td class="style15">
&nbsp;</td>
<td class="style32">
&nbsp;</td>
<td class="style17">
&nbsp;</td>
</tr>
<tr>
<td class="style10">
&nbsp;</td>
<td class="style11">
&nbsp;</td>
<td class="style15">
&nbsp;</td>
<td class="style33">
&nbsp;</td>
<td class="style23">
&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Menghitung Luas Persegi panjang

<%@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Hitung_Click(object sender, EventArgs e)
{
double panjang, lebar, luas;
panjang = Convert.ToDouble(txtpanjang.Text);
lebar = Convert.ToDouble(txtlebar.Text);
luas = panjang * lebar;
lbluas.Text = Convert.ToString(luas);
}
protected void Clear_Click(object sender, EventArgs e)
{
txtpanjang.Text = "";
txtlebar.Text = "";
lbluas.Text = "0";

txtpanjang.Focus();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
Panjang&nbsp; :&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtpanjang" runat="server"></asp:TextBox>
<p>
Lebar&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="txtlebar" runat="server"></asp:TextBox>
</p>
<asp:Button ID="Hitung" runat="server" onclick="Hitung_Click" Text="Hitung"
Width="63px" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Clear" runat="server" style="margin-left: 12px" Text="Clear"
Width="77px" onclick="Clear_Click" />
<div style="margin-left: 40px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;
</div>
<p>
&nbsp;&nbsp; Luas :&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="lbluas" runat="server" Text="luas"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
</form>
</body>
</html>

Menghitung Luas Segitiga

<%@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Hitung_Click(object sender, EventArgs e)
{
double alas, tinngi, luas;
alas = Convert.ToDouble(txtalas.Text);
tinngi = Convert.ToDouble(txttinggi.Text);
luas = 0.5 * alas * tinngi;
lbhasil.Text = Convert.ToString(luas);
}
protected void Clear_Click(object sender, EventArgs e)
{

txtalas.Text = "";
txttinggi.Text = "";
lbhasil.Text = "0";
txtalas.Focus();
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>1215625</title>
</head>
<body>
<form id="form1" runat="server">
MENCARI LUAS SEGITIGA<br />
<br />
Luas Alas&nbsp; :&nbsp;&nbsp;
<asp:TextBox ID="txtalas" runat="server"></asp:TextBox>
<p>
Tinggi&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;&nbsp;
<asp:TextBox ID="txttinggi" runat="server"></asp:TextBox>
</p>
<asp:Button ID="Hitung" runat="server" onclick="Hitung_Click" Text="Hitung"
Width="77px" />
&nbsp;&nbsp;&nbsp;
<asp:Button ID="Clear" runat="server" style="margin-left: 12px" Text="Clear"
Width="77px" onclick="Clear_Click" />
<div style="margin-left: 40px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;
</div>
<p>
&nbsp; Result&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="lbhasil" runat="server"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
</form>
</body>
</html>

Contoh Tombol

<%@ Page Language="C#" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
}

Label1.Text = "NAME: Rio Putra";

protected void Button2_Click(object sender, EventArgs e)


{
Label2.Text = "NIM:1215625";
}
protected void Button3_Click(object sender, EventArgs e)
{
}

Label3.Text = "ADDRESS: TAMAN SURYA INDAH BLOK Q-16";

protected void Button4_Click(object sender, EventArgs e)


{
Label1.Text = null;
Label2.Text = null;
Label3.Text = null;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Design Master</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="NAME" OnClick="Button1_Click"
BackColor="#33CC33" Width="75px" />
<asp:Button ID="Button2" runat="server" Text="NIM" OnClick="Button2_Click"
BackColor="#33CC33" Width="75px" />
<asp:Button ID="Button3" runat="server" Text="ADDRESS" OnClick="Button3_Click"
BackColor="#33CC33" Width="75px" />
<asp:Button ID="Button4" runat="server" Text="CLEAR" OnClick="Button4_Click"
BackColor="#33CC33" Width="75px" />
</div>
<asp:Label ID="Label1" runat="server" ForeColor="#33CC33"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server" ForeColor="#33CC33"></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" ForeColor="#33CC33"></asp:Label>

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

Contoh Table

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master"


AutoEventWireup="true" CodeFile="buku.aspx.cs" Inherits="buku" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Repeater ID="myRepeater" runat="server">
<HeaderTemplate>
<table width="800" border="1">
<tr>
<th>ID Buku</th>
<th>Jenis</th>
<th>Judul</th>
<th>Pengarang</th>
<th>Penerbit</th>
<th>Tahun</th>
<th>Keterangan</th>
</tr>
</HeaderTemplate>
<itemTemplate>
<tr>
<td><%# Eval("id_buku") %></td>
<td><%# Eval("jenis") %></td>
<td><%# Eval("judul") %></td>
<td><%# Eval("pengarang") %></td>
<td><%# Eval("penerbit") %></td>
<td><%# Eval("tahun_cetak") %></td>
<td><%# Eval("keterangan") %></td>
</tr>
</itemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Content>

Contoh Program Table Buku


using
using
using
using
using
using
using

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Inisialisasi koneksi
conn = new SqlConnection("Server=Lenovo-PC\\Lenovo;" +
"Database=perpustakaan;integrated security=True" );
// Menentukan query SQL
comm = new SqlCommand("SELECT id_buku, jenis, judul, penerbit, tahun_cetak,
pengarang, keterangan " + "FROM buku");
//jalankan dalam pengujian kesalahan
try
{
conn.Open();
reader = comm.ExecuteReader();

myRepeater.DataSource = reader; myRepeater.DataBind();


reader.Close();

}
}

}
catch
{
Response.Write("Gagal Mengambil Data." +ex);
}
finally
{
conn.Close();
}