ASP.net code C# คิดเกรดแบบขำๆ

posted on 02 Oct 2009 15:06 by techinnoreview  in MITT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void OK_Click(object sender, EventArgs e)
    {
        //รับค่า
        int score = Convert.ToInt32(Score.Text);
        if (score < 0 || score >100)
        {
            Result.Text = "มั่วแล่ว";
            Result.ForeColor = Color.Red;
        }
        else if (score < 50)
        {
            Result.Text = "F";
            Result.ForeColor = Color.Red;
        }
        else if (score < 60)
        {
            Result.Text = "D";
            Result.ForeColor = Color.Orange;
        }
        else if (score < 70)
        {
            Result.Text = "C";
            Result.ForeColor = Color.Yellow;
        }
        else if (score < 80)
        {
            Result.Text = "B";
            Result.ForeColor = Color.Blue;
        }
        else if (score == 100)
        {
            Result.Text = "โคตรเทพ";
            Result.ForeColor = Color.Black;
        }
        else 
        {
            Result.Text = "A";
            Result.ForeColor = Color.Green;
        }
    }
}
 
 
ฝั่งเว็บ
 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ifelse.aspx.cs" Inherits="Default2" %>
<%@ Import Namespace = "System.Drawing" %>
<!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>If Else</title>
</head>
<body bgcolor="White" background="Back.PNG" text="#ffffff">
    <form id="form1" runat="server">
    <div>
    
        If Else<br />
        <br />
        <br />
        <br />
    
    </div>
    &nbsp;&nbsp;
    <br />
    <asp:Label ID="Result" runat="server" BorderStyle="Groove" BorderWidth="2px" 
        Width="200px" BackColor="#CCFFFF" Font-Bold="True" Font-Size="Medium"></asp:Label>
    <br />
    <br />
    Score :&nbsp;&nbsp;     <asp:TextBox ID="Score" runat="server"></asp:TextBox>
&nbsp;
    <br />
    <br />
    <asp:Button ID="OK" runat="server" onclick="OK_Click" Text="Submit" />
    </form>
</body>
</html>
 

Comment



smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry

Tweet

อารายหว่า
มีเเต่โค้ดembarrassed

#1 By Sugar on 2009-10-02 15:10

ก็ CODE หนิครับ

#2 By Auttapong Maesincee on 2009-10-02 15:39

แจ่มเลยครับ...ขอบคุณมาก

#3 By Searchเจอ (125.26.252.116) on 2009-10-10 12:27

ถ้าอยากให้เรียกค่าจากฐานข้อมูลทำไงคะ
else if (score < 60)
ตรง 60 นี่อะ อยากให้เรียกจากฐานข้อมูลเอา
แบบว่ากำหนดให้เปลี่ยนคะแนนเองได้

#4 By T (117.47.218.249) on 2009-10-14 21:52