【问题标题】:FIlter expression not working Sqldatasource过滤器表达式不起作用Sqldatasource
【发布时间】:2011-07-06 13:46:26
【问题描述】:

这是我的带有过滤器表达式的 sqldatasource

   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
                    SelectCommand="SELECT [id], [title], [client], [projectmanager], [project_scope], [project_materials], [project_gating], [project_cavities], [project_file], [project_otherdetails], [priority], [commodity], [status], [start_date], [end_date] FROM [project_details]" 
                    ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
                    EnableCaching="True" CacheDuration="1000" 
FilterExpression="title= '{2}'">



 <FilterParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="mainsearch" 
                        PropertyName="SelectedItem.Value" />
                    <asp:ControlParameter ControlID="TextBox2" Name="start_date" 
                        PropertyName="Text" />
                    <asp:ControlParameter ControlID="TextBox3" Name="end_date" 
                        PropertyName="Text" />
    <asp:ControlParameter   

                                  </FilterParameters>



    </asp:SqlDataSource>

当我在 Textbox2 中输入值时,它不起作用可能是什么问题

【问题讨论】:

  • 请不要再问同样的问题。编辑您的第一个问题。
  • 对不起,以后会做的。你有这个问题的任何解决方案

标签: c# asp.net sql visual-studio


【解决方案1】:

因为您在 SQL 数据源 SelectParameters 中设置了 ControlID="TextBox1",但您在 Textbox2 中设置了值。你必须把它改成&lt;asp:ControlParameter ControlID="TextBox2"

<asp:ControlParameter ControlID="TextBox2" DefaultValue="%" Name="title" 
            PropertyName="Text" Type="String" />

编辑:在您的 cmets 之后,您想要清除 Where Clause。你可以这样做......

protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    SqlDataSource1.SelectParameters.Clear(); // First Clear the Selected parameters
    SqlDataSource1.SelectCommand = "SELECT [id], [title], [client], [projectmanager], [project_scope], [project_materials], [project_gating], [project_cavities], [project_file], [project_otherdetails], [priority], [commodity], [status], [start_date], [end_date] FROM [project_details]";
}

【讨论】:

  • select参数与filter参数无关,select参数用于where语句
  • 我说的是 where 声明。
  • 但我的问题是关于过滤器表达式。从代码中删除 where 语句。之后它也不起作用。
  • 您想从查询中删除过滤表达式或 Where 子句?
  • 过滤器表达式很烂,现在我正在使用 where 子句来解决问题
猜你喜欢
  • 1970-01-01
  • 2017-02-19
  • 2016-03-18
  • 1970-01-01
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-27
相关资源
最近更新 更多