0

自動生成された列を含むインフラジスティックス グリッドがあります。コード ビハインドからストアド プロシージャの結果をグリッドに割り当てるにはどうすればよいですか

      <ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server"  Width="100%">
    <Behaviors>
        <ig:Sorting>
        </ig:Sorting>
    </Behaviors>
</ig:WebDataGrid>

コードビハインドは

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EntityName.Text = DropDownList1.SelectedItem.Text;
        string @RegardingObjectName = DropDownList1.SelectedItem.Text.Trim();
        String strConnString = ConfigurationManager.ConnectionStrings["LiveLeaseConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(strConnString);
        SqlCommand cmd = new SqlCommand();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "p_DataList_ByRegardingObject";
        cmd.Parameters.AddWithValue("@RegardingObjectName", @RegardingObjectName);
        cmd.Connection = con;
        try
        {              
            con.Open();
            EntityGrid.DataSource = cmd.ExecuteReader();
            EntityGrid.DataBind();

エンティティをパラメーターとしてストアド プロシージャに渡す必要があります。どうすればここでそれを行うことができますか?

リーダークローズエラーが発生しています

4

1 に答える 1

1

ControlParameterを追加する必要があります SelectParameters

<asp:ControlParameter Name="entityId" 
ControlID="DropDownList1" 
PropertyName="SelectedItem" Type="String" />

この質問も参照してくださいSqlDataSourceでストアドプロシージャのパラメータ値を指定する方法

ここに示すように、選択イベントを使用して編集できます

C# のコード ビハインドで SQLdatasource を記述して、コード ビハインド値を使用する

select パラメータを次のように追加することもできます。

EntityGrid.SelectParameters.Add("entityId", DropDownList1.SelectedItem.Text);

「entityId」の名前を、SP で使用するパラメーターの名前に変更するだけです

編集2

それ以外の

EntityGrid.DataSource = cmd.ExecuteReader();
            EntityGrid.DataBind();

これを試して

SqlDataReader reader = cmd.ExecuteReader();
    using (reader)
    {
      DataTable table = new DataTable();
      table.Load(reader);
      EntityGrid.DataSource = table;
    }

詳細については、このリンクを参照してください:
http://mentaljetsam.wordpress.com/2008/11/20/loading-an-sqldatareader-into-a-datagridview/

于 2013-05-02T17:38:12.757 に答える