【发布时间】:2012-02-25 17:01:30
【问题描述】:
我正在关注HERE 列出的可搜索网格视图代码。我在使用FilterExpression 时遇到问题。我得到了例外:
“名称”运算符后缺少操作数...发生异常时, FilterExpression = " WHERE Name like 'spencer%'"
异常发生在以下代码中:
protected void BindSGVData()
{
//hfSearchText has the search string returned from the grid.
if (hfSearchText.Value != "")
{
RidesSQL.FilterExpression = " WHERE " + hfSearchText.Value; //EXCEPTION HERE!
}
DataView dv = (DataView)RidesSQL.Select(new DataSourceSelectArguments());
//hfSort has the sort string returned from the grid.
if (hfSort.Value != "")
{
dv.Sort = hfSort.Value;
}
RideSGV.DataSource = dv;
try
{
RideSGV.DataBind();
}
catch (Exception exp)
{
//If databinding threw exception bcoz current page index is > than available page index
RideSGV.PageIndex = 0;
RideSGV.DataBind();
}
finally
{
//Select the first row returned
if (RideSGV.Rows.Count > 0)
RideSGV.SelectedIndex = 0;
}
}
有什么想法吗?
【问题讨论】:
-
@M.Babcock 你先生是我的英雄!大声笑,这里是为了不抓住明显的...我已经将它从编辑选择命令更改为添加过滤器,是的,不需要 WHERE.. 我太忙于修改操作数而没有注意到。必须回答一个答案,这样我就可以给你一个大的绿色复选标记! ( :
标签: c# asp.net sql search sqldatasource