我想过滤我的gridview结果,所以我想在运行时定义SqlDataSource1.FilterExpression
,但它给了我错误:
missing operand after "%my search name%" operater
。
SqldataSource1.FilterExpression =“[user_name]喜欢N'%{1}%'和[user_family]喜欢N'%{2}%'”; GridView1.DataBind();
这是我的代码: 它给了我错误案例2:
int search = (int)ViewState["se"];
switch (search)
{
case 0:
{
SqlDataSource1.SelectCommand = "SELECT [id], [user_email], [user_password], [user_name], [user_family], [user_activation],[nick_name] FROM [users]";
GridView1.DataBind();
}
break;
case 1:
{
SqlDataSource1.FilterExpression = "user_email like '%{0}%'";
GridView1.DataBind();
}
break;
case 2:
{
SqlDataSource1.FilterExpression = "user_name like N'%{1}%' and user_family like N'%{2}%'";
GridView1.DataBind();
}
break;
default:
break;
}
我在sqldatasource1中的过滤器参数:
<FilterParameters>
<asp:ControlParameter ControlID="TextBox1" Name="n" PropertyName="Text" ConvertEmptyStringToNull="false"/>
<asp:ControlParameter ControlID="TextBox13" Name="n2" PropertyName="Text" ConvertEmptyStringToNull="false" />
<asp:ControlParameter ControlID="TextBox14" Name="n3" PropertyName="Text" ConvertEmptyStringToNull="false" />
</FilterParameters>