If - Else ASP.NET C# การสร้างเงื่อนไขแบบ If - Else
If - Else คือ คำสั่งสำหรับการสร้างเงื่อนไขแบบหนึ่ง มีไว้สำหรับการควบคุมการทำงานของโปรแกรมให้เป็นไปตามที่กำหนด หรือตามที่ต้องการ
ตัวอย่างโปรแกรม .aspx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TEST._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:Label runat="server" ID="lbl"></asp:Label> </div> </form></body></html> |
ตัวอย่างโปรแกรม .aspx.cs
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
| using System;using System.Collections;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;namespace TEST{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { int a = 10; if (a >= 10) { lbl.Text = "a >= 10"; } else { lbl.Text = "a < 10"; } } }} |
ผลลัพธ์
1
| a >= 10 |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น