Bu yazımızda ASP.NET ile 2 yazılı ve 1 sözlü notu girilen bir öğrencinin ortalamasının hesaplanması ve Ortalaması 50′ den küçükse “KALDI” büyükse “GEÇTİ” yazdıran bir örnek oluşturacağız.

Formumuzu yukarıdaki gibi tasarlıyoruz. Bu örneğimizde kontrollerimizi Table içine yerleştirdik.

WebForm.aspx kodlarımız:
WebForm.aspx.cs kodlarımız:
Ekran Çıktısı:


Formumuzu yukarıdaki gibi tasarlıyoruz. Bu örneğimizde kontrollerimizi Table içine yerleştirdik.

WebForm.aspx kodlarımız:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AspYaziliOrtalama.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style type="text/css"> .auto-style1 { width: 38%; } .auto-style2 { height: 23px; } .auto-style3 { width: 97px; } .auto-style4 { height: 23px; width: 97px; } </style> </head> <body> <form id="form1" runat="server"> <div> <table class="auto-style1"> <tr> <td class="auto-style3">1. Yazılı</td> <td> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style3">2. Yazılı</td> <td> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style3">1. Sözlü</td> <td> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </td> </tr> <tr> <td class="auto-style4"></td> <td class="auto-style2"> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Hesapla" /> </td> </tr> <tr> <td class="auto-style3"> </td> <td> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </td> </tr> <tr> <td class="auto-style3"> </td> <td> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> </td> </tr> </table> </div> </form> </body> </html> |
WebForm.aspx.cs kodlarımız:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | protected void Button1_Click(object sender, EventArgs e) { double y1, y2, s1, ort; y1 = Convert.ToDouble(TextBox1.Text); y2 = Convert.ToDouble(TextBox2.Text); s1 = Convert.ToDouble(TextBox3.Text); ort = (y1 + y2 + s1) / 3; Label1.Text = "Ortalama = " + Math.Round(ort,2); if (ort < 50) { Label2.Text = "KALDI"; } else { Label2.Text = "GEÇTİ"; } } |
Ekran Çıktısı:
