Pada pelajaran ASP.Net yang didapat hari ini, kita diajari membuat program sederhana, yaitu kalkulator yang masih sederhana, tampilannya kurang lebih seperti di atas. Dan ini codingnya pada bagian default .aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>
<h2>KALKULATOR SEDERHANA</h2>
<form id="form1" runat="server">
<div>
Bilangan 1 : <asp:TextBox ID="bil1" runat="server" ontextchanged="TextBox1_TextChanged1"></asp:TextBox>
</div>
<p>
Bilangan 2 : <asp:TextBox ID="bil2" runat="server"></asp:TextBox>
</p>
<p>
Hasil : <asp:TextBox ID="hasil" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="jum" runat="server" Text="+" Width="30px" onclick="jum_Click" />
<asp:Button ID="min" runat="server" Text="-" Width="30px" onclick="min_Click" />
<asp:Button ID="kali" runat="server" Text="*" Width="30px" onclick="kali_Click" />
<asp:Button ID="bagi" runat="server" Text="/" Width="30px" onclick="bagi_Click" />
</p>
</form>
</body>
</html>
<!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>
<h2>KALKULATOR SEDERHANA</h2>
<form id="form1" runat="server">
<div>
Bilangan 1 : <asp:TextBox ID="bil1" runat="server" ontextchanged="TextBox1_TextChanged1"></asp:TextBox>
</div>
<p>
Bilangan 2 : <asp:TextBox ID="bil2" runat="server"></asp:TextBox>
</p>
<p>
Hasil : <asp:TextBox ID="hasil" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button ID="jum" runat="server" Text="+" Width="30px" onclick="jum_Click" />
<asp:Button ID="min" runat="server" Text="-" Width="30px" onclick="min_Click" />
<asp:Button ID="kali" runat="server" Text="*" Width="30px" onclick="kali_Click" />
<asp:Button ID="bagi" runat="server" Text="/" Width="30px" onclick="bagi_Click" />
</p>
</form>
</body>
</html>
Dan ini coding di default.aspx.cs
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged1(object sender, EventArgs e)
{
}
protected void jum_Click(object sender, EventArgs e)
{
/*
int a;
int b;
int c;
a = Convert.ToInt32(bil1.Text);
b = Convert.ToInt32(bil2.Text);
c = a + b;
hasil.Text = Convert.ToString;
*/
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) + Convert.ToInt32(bil2.Text));
}
protected void min_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) - Convert.ToInt32(bil2.Text));
}
protected void kali_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) * Convert.ToInt32(bil2.Text));
}
protected void bagi_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) / Convert.ToInt32(bil2.Text));
}
}
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged1(object sender, EventArgs e)
{
}
protected void jum_Click(object sender, EventArgs e)
{
/*
int a;
int b;
int c;
a = Convert.ToInt32(bil1.Text);
b = Convert.ToInt32(bil2.Text);
c = a + b;
hasil.Text = Convert.ToString;
*/
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) + Convert.ToInt32(bil2.Text));
}
protected void min_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) - Convert.ToInt32(bil2.Text));
}
protected void kali_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) * Convert.ToInt32(bil2.Text));
}
protected void bagi_Click(object sender, EventArgs e)
{
hasil.Text = Convert.ToString(Convert.ToInt32(bil1.Text) / Convert.ToInt32(bil2.Text));
}
}
Tidak ada komentar:
Posting Komentar