Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Gridview错误,在存储过程填充的Gridview中添加过滤器_C#_Asp.net_.net - Fatal编程技术网

C# Gridview错误,在存储过程填充的Gridview中添加过滤器

C# Gridview错误,在存储过程填充的Gridview中添加过滤器,c#,asp.net,.net,C#,Asp.net,.net,我有一个带有简单数据驱动gridview的.net Web表单: <asp:TextBox ID="txtCodeSearch" runat="server" Width="250px"></asp:TextBox> <br /> <asp:Button ID="btnCodeSearch" runat="server" Text="Search" CssClass="button-tiny" onclick="btnCo

我有一个带有简单数据驱动gridview的.net Web表单:

 <asp:TextBox ID="txtCodeSearch" runat="server" Width="250px"></asp:TextBox>
      <br />
<asp:Button ID="btnCodeSearch" runat="server" Text="Search" CssClass="button-tiny" 
        onclick="btnCodeSearch_Click" />

<asp:Gridview id="gvTest" runat="server">
<Columns>
<asp:CommandField ShowEditButton="True" HeaderText="Action" />
 <asp:BoundField DataField="Field1" />
 <asp:BoundField DataField="Field2" />
 <asp:BoundField DataField="CodeID" HeaderText="" ReadOnly="true" Visible="false" /> 
</Columns>
</asp:Gridview> 

<asp:SqlDataSource ID="dsTest" runat="server" 
            ConnectionString="<%$ ConnectionStrings:SQLConn %>" 
            SelectCommand="SelectCodes" 
            SelectCommandType="StoredProcedure"
            >
            <SelectParameters>
               <asp:QueryStringParameter Name="FooID" QueryStringField="FooID" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
简而言之,它在存储过程中运行一个不同的select语句,用一个额外的过滤器填充gridview。如果文本框中没有任何内容,则根据原始存储的过程填充gridview

这一切都很完美。问题是,gridview具有编辑功能。如果从第一个存储的过程(SelectCodes)填充网格时启用编辑模式,则该模式不会出现任何问题。如果我向下过滤网格,它由第二个存储过程(SelectCodesWithFilter)填充,然后进入编辑模式,它会告诉我,我试图向第一个存储过程添加太多参数


我被难住了,我不明白它为什么这么做。非常感谢您的帮助。

我没有尝试过,但我发现*这段代码可以切换到其他查询:

SqlDataSource1.SelectCommand = "SELECT x FROM MyTable";
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
SqlDataSource1.DataBind();
GridView1.DataBind();
我注意到SqlDataSource上的DataBind()命令位于GridView上的命令之前。这对你有影响吗


*来源:

为什么不使用SqlCommand对象,然后使用SqlAdapter填充数据表。。从这里,您知道可以对数据表进行过滤
SqlDataSource1.SelectCommand = "SELECT x FROM MyTable";
SqlDataSource1.Select(DataSourceSelectArguments.Empty);
SqlDataSource1.DataBind();
GridView1.DataBind();