ObjectListCommand 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
警告
The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.
表示 ObjectList ASP.NET 行動控制項的命令。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。
public ref class ObjectListCommand
[System.Web.UI.MobileControls.PersistName("Command")]
public class ObjectListCommand
[System.Web.UI.MobileControls.PersistName("Command")]
[System.Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class ObjectListCommand
[<System.Web.UI.MobileControls.PersistName("Command")>]
type ObjectListCommand = class
[<System.Web.UI.MobileControls.PersistName("Command")>]
[<System.Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")>]
type ObjectListCommand = class
Public Class ObjectListCommand
- 繼承
-
ObjectListCommand
- 屬性
範例
下列範例示範如何建立 ObjectListCommand 物件。 此範例是較大型、更完整的概觀範例的 ObjectList 一部分。
<%@ Page Language="C#"
Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server">
//System.Web.UI.MobileControls.ObjectListItem item;
//System.Web.UI.MobileControls.ObjectListItemCollection itemColl;
// Get the persisted array through postbacks.
ArrayList arr = new ArrayList();
public void Page_Load(Object sender, EventArgs e)
{
if (!IsPostBack)
{
// Create and fill the array
arr.Add(new Task("Tomorrow's work", "Yes", 1));
arr.Add(new Task("Today's work", "Yes", 1));
arr.Add(new Task("Yesterday's work", "No", 1));
// Persist the array in the Session object
Session["MyArrayList"] = arr;
// Associate and bind array to the
// ObjectList for each postback.
ObjectList1.DataSource = arr;
ObjectList1.LabelField = "TaskName";
ObjectList1.DataBind();
}
}
private void ItemCommand_Click(Object sender,
ObjectListCommandEventArgs e)
{
// Get the array from the Session object
arr = (ArrayList)Session["MyArrayList"];
// Remove selected item from the ObjectLis
int i = ObjectList1.SelectedIndex;
arr.RemoveAt(i);
Session["MyArrayList"] = arr;
// Re-Bind ObjectList to altered ArrayList.
ObjectList1.DataSource = arr;
ObjectList1.LabelField = "TaskName";
ObjectList1.DataBind();
ObjectList1.ViewMode = ObjectListViewMode.List;
}
void ItemCommands_Show(Object sender,
ObjectListShowCommandsEventArgs e)
{
// Check conditions, and add or remove
// commands in the detail view.
if (e.ListItem["Editable"].Equals("No"))
ObjectList1.Commands.RemoveAt(0);
else if (ObjectList1.Commands.Count < 1)
ObjectList1.Commands.Add(new
ObjectListCommand("Delete", "Delete"));
}
private class Task
{
private string _TaskName;
private string _Editable;
private int _Days;
public Task(string TaskName, string Editable, int Days)
{
_TaskName = TaskName;
_Editable = Editable;
_Days = Days;
}
public string TaskName
{ get { return _TaskName; } }
public string Editable
{ get { return _Editable; } }
public int Days
{ get { return _Days; } }
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<mobile:Form runat="server" id="Form1" >
<mobile:ObjectList runat="server" id="ObjectList1"
OnItemCommand="ItemCommand_Click"
OnShowItemCommands="ItemCommands_Show" >
<Command Name="Delete" Text="Delete" />
</mobile:ObjectList>
<mobile:Label runat="server" id="Label1" />
<mobile:Label runat="server" id="Label2" />
</mobile:Form>
</body>
</html>
<%@ Page Language="VB"
Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile"
Namespace="System.Web.UI.MobileControls"
Assembly="System.Web.Mobile" %>
<script runat="server">
' System.Web.UI.MobileControls.ObjectListItem item
' System.Web.UI.MobileControls.ObjectListItemCollection itemColl
' Get the persisted array through postbacks.
Private arr As New ArrayList()
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
' Create and fill the array
arr.Add(new Task("Tomorrow's work", "Yes", 1))
arr.Add(new Task("Today's work", "Yes", 1))
arr.Add(new Task("Yesterday's work", "No", 1))
' Persist the array in the Session object
Session("MyArrayList") = arr
' Associate and bind array to the
' ObjectList for each postback.
ObjectList1.DataSource = arr
ObjectList1.LabelField = "TaskName"
ObjectList1.DataBind()
End If
End Sub
Private Sub SelectCommand(ByVal sender As Object, _
ByVal e As ObjectListCommandEventArgs)
' Get the array from the Session object
arr = CType(Session("MyArrayList"), ArrayList)
' Remove selected item from the ObjectLis
Dim i As Integer = ObjectList1.SelectedIndex
arr.RemoveAt(i)
Session("MyArrayList") = arr
' Re-Bind ObjectList to altered ArrayList.
ObjectList1.DataSource = arr
ObjectList1.LabelField = "TaskName"
ObjectList1.DataBind()
ObjectList1.ViewMode = ObjectListViewMode.List
End Sub
Public Sub ShowTaskDetail(ByVal sender As Object, _
ByVal e As ObjectListShowCommandsEventArgs)
' Check conditions, and add or remove
' commands in the detail view.
If e.ListItem("Editable").Equals("No") Then
ObjectList1.Commands.RemoveAt(0)
ElseIf ObjectList1.Commands.Count < 1 Then
ObjectList1.Commands.Add(New ObjectListCommand("Delete", "Delete"))
End If
End Sub
Private Class Task
Private _TaskName As String
Private _Editable As String
Private _Days As Integer
Public Sub New(ByVal TaskName As String, _
ByVal Editable As String, ByVal Days As Integer)
_TaskName = TaskName
_Editable = Editable
_Days = Days
End Sub
Public ReadOnly Property TaskName() As String
Get
Return _TaskName
End Get
End Property
Public ReadOnly Property Editable() As String
Get
Return _Editable
End Get
End Property
Public ReadOnly Property Days() As Integer
Get
Return _Days
End Get
End Property
End Class
</script>
<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
<mobile:Form runat="server" id="Form1" >
<mobile:ObjectList runat="server" id="ObjectList1"
OnItemCommand="SelectCommand" OnShowItemCommands="ShowTaskDetail" >
<Command Name="Delete" Text="Delete" />
</mobile:ObjectList>
<mobile:Label runat="server" id="Label1" />
<mobile:Label runat="server" id="Label2" />
</mobile:Form>
</body>
</html>
備註
ObjectListCommand物件可以宣告為 <command>
宣告ObjectList內的專案。
ObjectListCommand也可以建構物件,並以程序設計方式加入至 ObjectList,方法是將它加入至控件Commands的成員集合。
建構函式
ObjectListCommand() |
已淘汰.
初始化 ObjectListCommand 類別的新執行個體。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。 |
ObjectListCommand(String, String) |
已淘汰.
初始化 ObjectListCommand 類別的新執行個體。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。 |
屬性
Name |
已淘汰.
取得命令的名稱。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。 |
Text |
已淘汰.
取得或設定要出現在命令中的文字。 預設為空字串。 這個 API 已經過時。 如需如何開發 ASP.NET 行動應用程式的資訊,請參閱 具有 ASP.NET 的Mobile Apps & Sites。 |
方法
Equals(Object) |
已淘汰.
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
已淘汰.
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
已淘汰.
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
已淘汰.
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
已淘汰.
傳回代表目前物件的字串。 (繼承來源 Object) |