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;
}
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):