这是我的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中输入值时,它不起作用可能是什么问题
答案 0 :(得分:1)
因为您在SQL数据源ControlID="TextBox1"
中设置了SelectParameters
,但是您要在Textbox2
中设置值。您必须将其更改为<asp:ControlParameter ControlID="TextBox2"
<asp:ControlParameter ControlID="TextBox2" DefaultValue="%" Name="title"
PropertyName="Text" Type="String" />
修改:根据您的评论,您要清除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]";
}