新しい StateItem オブジェクトを StateBag オブジェクトに追加します。項目が StateBag 内に既に存在する場合は、項目の値を更新します。
Public Function Add( _
ByVal key As String, _ ByVal value As Object _) As StateItem
[C#]
public StateItem Add(stringkey,objectvalue);
[C++]
public: StateItem* Add(String* key,Object* value);
[JScript]
public function Add(
key : String,value : Object) : StateItem;
パラメータ
- key
StateItem オブジェクトの属性名。 - value
StateBag に追加する項目の値。
戻り値
ビューステートに追加されたオブジェクトを表す StateItem オブジェクトを返します。
例外
例外の種類 | 条件 |
---|---|
ArgumentException | key が null の場合、または key 内の文字数が 0 の場合にスローされます。 |
使用例
[Visual Basic, C#, JScript] Add メソッドを使用する例を次に示します。
Sub GotoButton_Click(sender As Object, e As EventArgs)
Dim invoice As InvoiceRecord = GetInvoice(GotoId.Text)
GotoId.Text = ""
' Use the invoice Id as the key for the invoice
' name in the StateBag.
ViewState.Add(invoice.Id, invoice.Name)
DisplayInvoice(invoice)
selectedMruValue = invoice.Id
End Sub 'GotoButton_Click
[C#]
void GotoButton_Click(Object sender, EventArgs e) {
InvoiceRecord invoice = GetInvoice(GotoId.Text);
GotoId.Text = "";
// Use the invoice Id as the key for the invoice
// name in the StateBag.
ViewState.Add(invoice.Id, invoice.Name);
DisplayInvoice(invoice);
selectedMruValue = invoice.Id;
}
[JScript]
function GotoButton_Click(sender, e : EventArgs) {
var invoice : InvoiceRecord = GetInvoice(GotoId.Text);
GotoId.Text = "";
// Use the invoice Id as the key for the invoice
// name in the StateBag.
ViewState.Add(invoice.Id, invoice.Name);
DisplayInvoice(invoice);
selectedMruValue = invoice.Id;
}
[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
StateBag クラス | StateBag メンバ | System.Web.UI 名前空間 | Web フォームの状態管理の概要 | Item | Clear | Remove