DetailsViewInsertEventArgs.CommandArgument プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DetailsViewInsertEventArgs.CommandArgument プロパティの意味・解説 

DetailsViewInsertEventArgs.CommandArgument プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

DetailsView コントロール渡される挿入処理のコマンド引数取得します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim instance As DetailsViewInsertEventArgs
Dim value As Object

value = instance.CommandArgument
public Object CommandArgument { get; }
public:
property Object^ CommandArgument {
    Object^ get ();
}
/** @property */
public Object get_CommandArgument ()
public function get CommandArgument
 () : Object

プロパティ
DetailsView コントロール渡される挿入処理のコマンド引数

解説解説
使用例使用例

Button コントロールの CommandArgument プロパティ設定し、ItemInserting イベント中に値を取得して使用する方法コード例次に示します

<%@ Page Language="VB" %>

<script runat="server">
    Sub CustomerDetailsView_ItemInserting(ByVal
 sender As Object, ByVal
 e As DetailsViewInsertEventArgs)
  
        ' Use the Values property to retrieve the key field value.
        Dim keyValue As String
 = e.Values("CustomerID").ToString()

        If CStr(e.CommandArgument) = "CheckID"
 Then
            ' Insert the record only if the key field is four characters
            ' long; otherwise, cancel the insert operation.
            If keyValue.Length = 4 Then
                ' Change the key field value to upper case before inserting
 
                ' the record in the data source.
                e.Values("CustomerID") = keyValue.ToUpper()

                MessageLabel.Text = ""
            Else
                MessageLabel.Text = "The key field must have four
 digits."
                e.Cancel = True
            End If
        End If
    End Sub


</script>

<html>
  <body>
    <form id="Form1" runat="server">
        
      <h3>DetailsViewInsertEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true" AutoGenerateInsertButton=true
          oniteminserting="CustomerDetailsView_ItemInserting"
 
          runat="server">

            <Fields>
                <asp:TemplateField >
                  <InsertItemTemplate>
                    <asp:Button ID="Button1" CommandName="Insert"
 CommandArgument="CheckID" 
                      runat="server" Text="Insert
 with ID Check" BackColor=green />
                  </InsertItemTemplate>
                </asp:TemplateField>
            </Fields>               
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- This example uses Microsoft SQL Server and connects
  -->
        <!-- to the Northwind sample database. Use an ASP.NET
     -->
        <!-- expression to retrieve the connection string
 value   -->
        <!-- from the web.config file.                            -->
        <asp:sqldatasource id="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address],
 [City], [PostalCode], [Country] From [Customers]"
          insertcommand="INSERT INTO [Customers]([CustomerID],
 [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID,
 @CompanyName, @Address, @City, @PostalCode, @Country)"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
          runat="server"/>
            
      </form>
  </body>
</html>
<%@ Page language="C#" %>

<script runat="server">

  void CustomerDetailsView_ItemInserting(Object sender, DetailsViewInsertEventArgs
 e)
  {
    // Use the Values property to retrieve the key field value.
    String keyValue = e.Values["CustomerID"].ToString();

    if (((string)(e.CommandArgument)) == "CheckID")
    {
        // Insert the record only if the key field is four characters
        // long; otherwise, cancel the insert operation.
        if (keyValue.Length == 4)
        {
            // Change the key field value to upper case before inserting
 
            // the record in the data source.
            e.Values["CustomerID"] = keyValue.ToUpper();

            MessageLabel.Text = "";
        }
        else
        {
            MessageLabel.Text = "The key field must have four digits.";
            e.Cancel = true;
        }
    }
  }

</script>

<html>
  <body>
    <form id="Form1" runat="server">
        
      <h3>DetailsViewInsertEventArgs Example</h3>
                
        <asp:detailsview id="CustomerDetailsView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogeneraterows="true"
          allowpaging="true" AutoGenerateInsertButton=true
          oniteminserting="CustomerDetailsView_ItemInserting" 
          runat="server">

            <Fields>
                <asp:TemplateField >
                  <InsertItemTemplate>
                    <asp:Button CommandName="Insert" CommandArgument="CheckID"
 
                      runat="server" Text="Insert with ID Check"
 BackColor=green />
                  </InsertItemTemplate>
                </asp:TemplateField>
            </Fields>               
        </asp:detailsview>
        
        <asp:label id="MessageLabel"
          forecolor="Red"
          runat="server"/>
            
        <!-- This example uses Microsoft SQL Server and connects  -->
        <!-- to the Northwind sample database. Use an ASP.NET     -->
        <!-- expression to retrieve the connection string value
   -->
        <!-- from the web.config file.                            -->
        <asp:sqldatasource id="DetailsViewSource"
          selectcommand="Select [CustomerID], [CompanyName], [Address], [City],
 [PostalCode], [Country] From [Customers]"
          insertcommand="INSERT INTO [Customers]([CustomerID], [CompanyName],
 [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName,
 @Address, @City, @PostalCode, @Country)"
          connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
 
          runat="server"/>
            
      </form>
  </body>
</html>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DetailsViewInsertEventArgs クラス
DetailsViewInsertEventArgs メンバ
System.Web.UI.WebControls 名前空間
DetailsView クラス
DetailsViewInsertEventHandler
DetailsView.ItemInserting イベント
Values



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DetailsViewInsertEventArgs.CommandArgument プロパティ」の関連用語

DetailsViewInsertEventArgs.CommandArgument プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DetailsViewInsertEventArgs.CommandArgument プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS