ObjectDataSource FilterExpression 不适用于多个参数
我有一个可以很好地绑定到我的 GridView 的 ObjectDataSource。
我还有两个调用 ApplyFilterExpression 函数的下拉列表框。
它们都是独立工作的,但是当我设置两个下拉列表的值时,我没有得到任何结果。但我知道应该有结果。我在这里做错了什么?
<asp:ObjectDataSource ID="dsLogs" runat="server" SelectMethod="GetDTAll"
TypeName="LogManager.LogRepository"
SelectCountMethod="GetAllCount" >
<SelectParameters>
<asp:Parameter DefaultValue="DESC" Name="sortOrder" Type="String" />
<asp:Parameter DefaultValue="timestamp" Name="orderBy" Type="String" />
<asp:Parameter DefaultValue="1" Name="startRowIndex" Type="Int32" />
<asp:Parameter DefaultValue="1000" Name="maximumRows" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
private void ApplyFilterExpression()
{
dsLogs.FilterExpression = null;
bool hasFilter = false;
if (ddlTypes.SelectedIndex != 0)
{
dsLogs.FilterExpression = "type='" + ddlTypes.SelectedValue + "'";
hasFilter = true;
}
if (ddlUsers.SelectedIndex != 0)
{
if (hasFilter)
{
dsLogs.FilterExpression += " AND username='" + ddlUsers.SelectedValue + "'";
}
else
{
dsLogs.FilterExpression = "username='" + ddlUsers.SelectedValue + "'";
hasFilter = true;
}
}
ViewState["FiltExp"] = (string)dsLogs.FilterExpression;
}
I have an ObjectDataSource that is binding to my GridView just fine.
I also have two dropdown list boxes that call an ApplyFilterExpression function.
They both work independently, but when i set both dropdown with values i get no results. But i KNOW that there should be results. What am i doing wrong here?
<asp:ObjectDataSource ID="dsLogs" runat="server" SelectMethod="GetDTAll"
TypeName="LogManager.LogRepository"
SelectCountMethod="GetAllCount" >
<SelectParameters>
<asp:Parameter DefaultValue="DESC" Name="sortOrder" Type="String" />
<asp:Parameter DefaultValue="timestamp" Name="orderBy" Type="String" />
<asp:Parameter DefaultValue="1" Name="startRowIndex" Type="Int32" />
<asp:Parameter DefaultValue="1000" Name="maximumRows" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
private void ApplyFilterExpression()
{
dsLogs.FilterExpression = null;
bool hasFilter = false;
if (ddlTypes.SelectedIndex != 0)
{
dsLogs.FilterExpression = "type='" + ddlTypes.SelectedValue + "'";
hasFilter = true;
}
if (ddlUsers.SelectedIndex != 0)
{
if (hasFilter)
{
dsLogs.FilterExpression += " AND username='" + ddlUsers.SelectedValue + "'";
}
else
{
dsLogs.FilterExpression = "username='" + ddlUsers.SelectedValue + "'";
hasFilter = true;
}
}
ViewState["FiltExp"] = (string)dsLogs.FilterExpression;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它可能与更新过滤器表达式有关,但我怀疑情况确实如此。
但是,您可以尝试以下代码,看看它是否可以解决您的问题(它将节省您一些代码并使其更易于理解和维护):
It could have something to do with updating filter expression, but I doubt that is the case.
However, you could try the following code to see if it resolves your problem (it will save you some code and make it easier to understand and maintain):