SHe*_*ema 2 c# sql asp.net search sqldatasource
我正在关注此处列出的可搜索网格视图代码.我在使用时遇到了麻烦FilterExpression
.我得到了例外:
'Name'运算符后缺少操作数...当异常发生时,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;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
RidesSQL.FilterExpression = " WHERE " + hfSearchText.Value; //EXCEPTION HERE!
Run Code Online (Sandbox Code Playgroud)
应该:
RidesSQL.FilterExpression = hfSearchText.Value; // NO EXCEPTION HERE!
Run Code Online (Sandbox Code Playgroud)