ICheckBoxControl 介面
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義控制項會實作的屬性和事件,以做為核取方塊。
public interface class ICheckBoxControl
public interface ICheckBoxControl
type ICheckBoxControl = interface
Public Interface ICheckBoxControl
- 衍生
範例
CheckBox 會實作 ICheckBoxControl。 下列程式碼範例示範如何讀取 屬性的值 Checked 並回應 CheckedChanged 事件。
<%@ Page Language="C#" AutoEventWireup="True" %>
<!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>CheckBox CheckedChanged Example</title>
<script runat="server">
void Check_Clicked(Object sender, EventArgs e)
{
// Calculate the subtotal and display the result in currency format.
// Include tax if the check box is selected.
Message.Text = CalculateTotal(checkbox1.Checked).ToString("c");
}
void Page_Load(Object sender, EventArgs e)
{
// Display the subtotal without tax when the page is first loaded.
if(!IsPostBack)
{
// Calculate the subtotal and display the result in currency format.
Message.Text = CalculateTotal(false).ToString("c");
}
}
double CalculateTotal(bool Taxable)
{
// Calculate the subtotal for the example.
double Result = 1.99 + 2.99 + 3.99;
// Add tax, if applicable.
if(Taxable)
{
Result += Result * 0.086;
}
return Result;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>CheckBox CheckedChanged Example</h3>
Select whether to include tax in the subtotal.
<br /><br />
<table border="1" cellpadding="5">
<tr>
<th colspan="2">
Shopping cart
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
$1.99
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
$2.99
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
$3.99
</td>
</tr>
<tr>
<td>
<b>Subtotal</b>
</td>
<td>
<asp:Label id="Message" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox id="checkbox1" runat="server"
AutoPostBack="True"
Text="Include 8.6% sales tax"
TextAlign="Right"
OnCheckedChanged="Check_Clicked"/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!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>CheckBox CheckedChanged Example</title>
<script runat="server">
Sub Check_Clicked(sender As Object, e As EventArgs)
' Calculate the subtotal and display the result in currency format.
' Include tax if the check box is selected.
Message.Text = CalculateTotal(checkbox1.Checked).ToString("c")
End Sub
Sub Page_Load(sender As Object, e As EventArgs)
' Display the subtotal without tax when the page is first loaded.
If Not IsPostBack Then
' Calculate the subtotal and display the result in currency format.
Message.Text = CalculateTotal(false).ToString("c")
End If
End Sub
Function CalculateTotal(Taxable As Boolean) As Double
' Calculate the subtotal for the example.
Dim Result As Double = 1.99 + 2.99 + 3.99
' Add tax, if applicable.
If(Taxable)
Result += Result * 0.086
End If
Return Result
End Function
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>CheckBox CheckedChanged Example</h3>
Select whether to include tax in the subtotal.
<br /><br />
<table border="1" cellpadding="5">
<tr>
<th colspan="2">
Shopping cart
</th>
</tr>
<tr>
<td>
Item 1
</td>
<td>
$1.99
</td>
</tr>
<tr>
<td>
Item 2
</td>
<td>
$2.99
</td>
</tr>
<tr>
<td>
Item 3
</td>
<td>
$3.99
</td>
</tr>
<tr>
<td>
<b>Subtotal</b>
</td>
<td>
<asp:Label id="Message" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2">
<asp:CheckBox id="checkbox1" runat="server"
AutoPostBack="True"
Text="Include 8.6% sales tax"
TextAlign="Right"
OnCheckedChanged="Check_Clicked"/>
</td>
</tr>
</table>
</form>
</body>
</html>
備註
介面 ICheckBoxControl 會定義屬性和事件,該屬性和事件必須實作,控制項才能做為網頁上的核取方塊。 屬性 Checked 可用來判斷是否已選取核取方塊,或以程式設計方式設定屬性。 CheckedChanged當貼文到伺服器之間的值變更時, Checked 就會引發 事件。
屬性
Checked |
取得或設定 ICheckBoxControl 控制項的值,指出控制項是否已選取。 |
事件
CheckedChanged |
發生於 Checked 屬性的值在送至伺服器的公佈間變更時。 |