This is my sqldatasource with filter expression
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [id], [title], [client], [projectmanager], [project_scope], [project_materials], [project_gating], [project_cavities], [project_fil开发者_如何学Ce], [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>
when i enter the value in Textbox2 it is not working what might be the problem
Because you set the ControlID="TextBox1"
in your SQL DataSource SelectParameters
, but you are setting the value in Textbox2
. You have to change it to <asp:ControlParameter ControlID="TextBox2"
<asp:ControlParameter ControlID="TextBox2" DefaultValue="%" Name="title"
PropertyName="Text" Type="String" />
Edit: Following your comments, you want to clear the Where Clause
. You can do like...
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]";
}
精彩评论