QueryStringParameter クラスとは? わかりやすく解説

QueryStringParameter クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

HTTP 要求クエリ文字列フィールドの値をパラメータ オブジェクトバインドます。

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

Public Class QueryStringParameter
    Inherits Parameter
Dim instance As QueryStringParameter
public class QueryStringParameter : Parameter
public ref class QueryStringParameter : public
 Parameter
public class QueryStringParameter extends Parameter
public class QueryStringParameter extends
 Parameter
解説解説

QueryStringParameter クラス使用すると、HTTP 要求クエリ文字列渡されフィールド値を、パラメータ クエリまたはコマンド使用するためのパラメータバインドできます。このフィールドは、QueryString コレクションから取得されます。QueryStringParameter指定されていても、対応するクエリ文字列の名前/値ペアが渡されないと、データパラメータバインドするコントロールか例外スローさます。同様にクエリ文字列フィールドの名前だけを渡して対応する値を渡さなかった場合データ表示されません。このような状況防ぐには必要に応じて DefaultValue設定します

QueryStringParameter クラスには、Parameter クラスから継承されプロパティ加えバインド先のクエリ文字列値の名前を識別する QueryStringField プロパティ用意されています。

メモ重要 :

QueryStringParameter は、クエリ文字列によって渡された値は一切検証せず、そのままの値を使用します多く場合データ ソース コントロール発生した SelectingUpdatingInsertingDeleting などのイベント処理することによって、QueryStringParameter の値をデータ ソース コントロール使用される前に検証できますパラメータの値が検証合格しなかった場合は、関連付けられた CancelEventArgs クラスCancel プロパティtrue設定することによって、データ操作キャンセルできます

使用例使用例

QueryStringParameter パラメータ宣言してフィルタとして使用し、GridView コントロールデータ表示する方法次のコード例示しますQueryStringParameter を AccessDataSource コントロールの FilterParameters コレクション宣言および追加すると、クエリ文字列フィールド "country" の値が対応する FilterExpression 文字列バインドされますパラメータに対して DefaultValue指定されていないため、"country" という名前のフィールドクエリ文字列渡されなかった場合AccessDataSource から NullReferenceException がスローさます。"country" という名前のフィールド渡され場合でも、対応する値が指定されなかった場合GridViewデータ表示されません。

<%@ Page language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML>
  <body>
    <form id="Form1" method="post"
 runat="server">

      <!-- Use a Query String with country=USA
 -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- Security Note: The AccessDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of
 input from the client. -->

      <asp:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, Address, PostalCode,
 Country FROM Employees"
        filterexpression="Country = '{0}'">
        <filterparameters>
          <asp:querystringparameter name="country"
 type="String" querystringfield="country"
 />
        </filterparameters>
      </asp:accessdatasource>

    </form>
  </body>
</HTML>
<%@ Page language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML>
  <body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String with country=USA -->
      <asp:gridview
        id ="GridView1"
        runat="server"
        datasourceid="MyAccessDataSource" />

<!-- Security Note: The AccessDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client. -->

      <asp:accessdatasource
        id="MyAccessDataSource"
        runat="server"
        datafile="Northwind.mdb"
        selectcommand="SELECT EmployeeID, LastName, Address, PostalCode, Country
 FROM Employees"
        filterexpression="Country = '{0}'">
        <filterparameters>
          <asp:querystringparameter name="country" type="String"
 querystringfield="country" />
        </filterparameters>
      </asp:accessdatasource>
    </form>
  </body>
</HTML>
<%@ Page language="VJ#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML>
  <body>
    <form id="Form1" method="post" runat="server">

      <!-- Use a Query String with country=USA -->
      <asp:GridView
        id ="GridView1"
        runat="server"
        DataSourceMode="DataSet"
        DataSourceID="MyAccessDataSource" />

      <asp:AccessDataSource
        id="MyAccessDataSource"
        runat="server"
        DataFile="Northwind.mdb"
        SelectCommand="SELECT EmployeeID, LastName, Address, PostalCode, Country
 FROM Employees"
        FilterExpression="Country = '@country'">
        <FilterParameters>
          <asp:QueryStringParameter Name="country" Type="String"
 QueryStringField="country" />
        </FilterParameters>
      </asp:AccessDataSource>
    </form>
  </body>
</HTML>

QueryStringParameter宣言しSQL パラメータ クエリ使ってAccess データベースデータ表示する方法次のコード例示しますGridView コントロール表示するレコードは、AccessDataSource によって取得されます。GridView は、ユーザーNorthwind Traders Orders テーブルレコード選択してボタンクリックしたときのレコード順序更新するためのユーザー インターフェイス備え編集することもできます

<%@Page  Language="VB" %>
<%@Import Namespace="System.Data"
 %>
<%@Import Namespace="System.Data.Common"
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat="server">
Private Sub UpdateRecords(source As
 Object, e As EventArgs)

  ' This method is an example of batch updating using a
  ' data source control. The method iterates through the rows
  ' of the GridView, extracts each CheckBox from the row and, if
  ' the CheckBox is checked, updates data by calling the Update
  ' method of the data source control, adding required parameters
  ' to the UpdateParameters collection.

  Dim cb As CheckBox
  Dim row As GridViewRow

  For Each row In GridView1.Rows

    cb = CType(row.Cells(0).Controls(1), CheckBox)
    If cb.Checked Then

      Dim oid As String
      oid = CType(row.Cells(1).Text, String)

      Dim param1 As New
 Parameter("date", TypeCode.DateTime, DateTime.Now.ToString())
      MyAccessDataSource.UpdateParameters.Add(param1)

      Dim param2 As New
 Parameter("orderid", TypeCode.String, oid)
      MyAccessDataSource.UpdateParameters.Add(param2)

      MyAccessDataSource.Update()
      MyAccessDataSource.UpdateParameters.Clear()
    End If
  Next
End Sub ' UpdateRecords
</SCRIPT>
<HTML>
  <BODY>
    <FORM runat="server">

<!-- Security Note: The SqlDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of
 input from the client.
     Security Note: To validate the value of
 the QueryStringParameter, handle the Selecting event. -->

      <asp:SqlDataSource
        id="MyAccessDataSource"
        runat="server"
        ProviderName="<%$ ConnectionStrings:MyPasswordProtectedAccess.providerName%>"
        ConnectionString="<%$ ConnectionStrings:MyPasswordProtectedAccess%>"
        SelectCommand="SELECT OrderID, OrderDate, RequiredDate,
 ShippedDate FROM Orders WHERE EmployeeID=?"
        UpdateCommand="UPDATE Orders SET ShippedDate=? WHERE OrderID
 = ?">
        <SelectParameters>
          <asp:QueryStringParameter Name="empId"
 QueryStringField="empId" />
        </SelectParameters>
      </asp:SqlDataSource>

      <asp:GridView
        id ="GridView1"
        runat="server"
        DataSourceID="MyAccessDataSource"
        AllowPaging="True"
        PageSize="10"
        AutoGenerateColumns="False">
          <columns>
            <asp:TemplateField HeaderText="">
              <ItemTemplate>
                <asp:CheckBox runat="server" />
              </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Order"
 DataField="OrderID" />
            <asp:BoundField HeaderText="Order Date"
 DataField="OrderDate" />
            <asp:BoundField HeaderText="Required Date"
 DataField="RequiredDate" />
            <asp:BoundField HeaderText="Shipped Date"
 DataField="ShippedDate" />
          </columns>
      </asp:GridView>

      <asp:Button
        id="Button1"
        runat="server"
        Text="Update the Selected Records As Shipped"
        OnClick="UpdateRecords" />

      <asp:Label id="Label1" runat="server"
 />

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="C#" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
private void UpdateRecords(Object source, EventArgs
 e)
{
  // This method is an example of batch updating using a
  // data source control. The method iterates through the rows
  // of the GridView, extracts each CheckBox from the row and, if
  // the CheckBox is checked, updates data by calling the Update
  // method of the data source control, adding required parameters
  // to the UpdateParameters collection.
  CheckBox cb;
  foreach(GridViewRow row in this.GridView1.Rows)
 {
    cb = (CheckBox) row.Cells[0].Controls[1];
    if(cb.Checked) {
      string oid = (string) row.Cells[1].Text;
      MyAccessDataSource.UpdateParameters.Add(new Parameter("date"
,TypeCode.DateTime,DateTime.Now.ToString()));
      MyAccessDataSource.UpdateParameters.Add(new Parameter("orderid"
,TypeCode.String,oid));
      MyAccessDataSource.Update();
      MyAccessDataSource.UpdateParameters.Clear();
    }
  }
}
</SCRIPT>

<HTML>
  <BODY>
    <FORM runat="server">

<!-- Security Note: The SqlDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the
 Selecting event. -->

      <asp:SqlDataSource
        id="MyAccessDataSource"
        runat="server"
        ProviderName="<%$ ConnectionStrings:MyPasswordProtectedAccess.providerName%>"
        ConnectionString="<%$ ConnectionStrings:MyPasswordProtectedAccess%>"
        SelectCommand="SELECT OrderID, OrderDate, RequiredDate, ShippedDate
 FROM Orders WHERE EmployeeID=?"
        UpdateCommand="UPDATE Orders SET ShippedDate=? WHERE OrderID = ?">
        <SelectParameters>
          <asp:QueryStringParameter Name="empId" QueryStringField="empId"
 />
        </SelectParameters>
      </asp:SqlDataSource>

      <asp:GridView
        id ="GridView1"
        runat="server"
        DataSourceID="MyAccessDataSource"
        AllowPaging="True"
        PageSize="10"
        AutoGenerateColumns="False">
          <columns>
            <asp:TemplateField HeaderText="">
              <ItemTemplate>
                <asp:CheckBox runat="server" />
              </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Order" DataField="OrderID"
 />
            <asp:BoundField HeaderText="Order Date" DataField="OrderDate"
 />
            <asp:BoundField HeaderText="Required Date" DataField="RequiredDate"
 />
            <asp:BoundField HeaderText="Shipped Date" DataField="ShippedDate"
 />
          </columns>
      </asp:GridView>

      <asp:Button
        id="Button1"
        runat="server"
        Text="Update the Selected Records As Shipped"
        OnClick="UpdateRecords" />

      <asp:Label id="Label1" runat="server" />

    </FORM>
  </BODY>
</HTML>
<%@Page  Language="VJ#" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.Common" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<SCRIPT runat="server">
    private void UpdateRecords(Object source,
 System.EventArgs e)
    {
        // This method is an example of batch updating using a
        // data source control. The method iterates through the rows
        // of the GridView, extracts each CheckBox from the row and,
 if
        // the CheckBox is checked, updates data by calling the Update
        // method of the data source control, adding required parameters
        // to the UpdateParameters collection.
        CheckBox cb;
        for (int iCtr = 0; 
                iCtr < this.GridView1.get_Rows().get_Count();
 iCtr++) {
            GridViewRow row = this.GridView1.get_Rows().get_Item(iCtr);
            cb = (CheckBox)row.get_Cells().get_Item(0).get_Controls().get_Item(1);
            if (cb.get_Checked()) {
                String oid = (String)(row.get_Cells().get_Item(1).get_Text());
                MyAccessDataSource.get_UpdateParameters().Add(new
 Parameter(
                    "date", System.TypeCode.DateTime, System.DateTime.get_Now().ToString()));
                MyAccessDataSource.get_UpdateParameters().Add(new
 Parameter(
                    "orderid", System.TypeCode.String, oid));
                MyAccessDataSource.Update();
                MyAccessDataSource.get_UpdateParameters().Clear();
            }
        }
    } //UpdateRecords
</SCRIPT>

<HTML>
  <BODY>
    <FORM runat="server">
<!-- Security Note: The SqlDataSource uses a QueryStringParameter,
     Security Note: which does not perform validation of input from the client.
     Security Note: To validate the value of the QueryStringParameter, handle the
 Selecting event. -->

      <asp:SqlDataSource
        id="MyAccessDataSource"
        runat="server"
        ProviderName="System.Data.OleDb"
        ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\uncpath\Northwind_PasswordProtected.mdb;Mode=3;Jet
 OLEDB:Database Password=myPassword;"
        SelectCommand="SELECT OrderID, OrderDate, RequiredDate, ShippedDate
 FROM Orders WHERE EmployeeID=?"
        UpdateCommand="UPDATE Orders SET ShippedDate=? WHERE OrderID = ?">
        <SelectParameters>
          <asp:QueryStringParameter Name="empId" QueryStringField="empId"
 />
        </SelectParameters>
      </asp:SqlDataSource>
      <asp:GridView
        id ="GridView1"
        runat="server"
        DataSourceID="MyAccessDataSource"
        AllowPaging="True"
        PageSize="10"
        AutoGenerateColumns="False">
          <Columns>
            <asp:TemplateField HeaderText="">
              <ItemTemplate>
                <asp:CheckBox runat="server" />
              </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField HeaderText="Order" DataField="OrderID"
 />
            <asp:BoundField HeaderText="Order Date" DataField="OrderDate"
 />
            <asp:BoundField HeaderText="Required Date" DataField="RequiredDate"
 />
            <asp:BoundField HeaderText="Shipped Date" DataField="ShippedDate"
 />
          </Columns>
      </asp:GridView>

      <asp:Button
        id="Button1"
        runat="server"
        Text="Update the Selected Records As Shipped"
        OnClick="UpdateRecords" />

      <asp:Label id="Label1" runat="server" />

    </FORM>
  </BODY>
</HTML>
継承階層継承階層
System.Object
   System.Web.UI.WebControls.Parameter
    System.Web.UI.WebControls.QueryStringParameter
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
QueryStringParameter メンバ
System.Web.UI.WebControls 名前空間
ControlParameter クラス
CookieParameter クラス
FormParameter クラス
ProfileParameter クラス
SessionParameter
その他の技術情報
データ ソース コントロールパラメータ使用



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

辞書ショートカット

すべての辞書の索引

「QueryStringParameter クラス」の関連用語

QueryStringParameter クラスのお隣キーワード
検索ランキング

   

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



QueryStringParameter クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS