How to use Dynamic Filter on ObjectDataSource
Hi,
I also have a similar kind of requirements, if possible please let me know how can do this...
Issue Details: Please let me know, in case my question is not clear.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFieldName As String
strFieldName = DropDownList1.SelectedValue
iStrFilter = strFieldName & " Like '" & txtSearch.Text.ToString() & "%'"
HiddenField1.Value = iStrFilter
If iStrFilter <> "" Then
ObjectDataSource1.FilterExpression = iStrFilter '"FirstName Like '" & iStrFilter & "%'"
Else
ObjectDataSource1.FilterExpression = ""
End If
GridView1.DataBind()
End Sub
I have 2 external textboxes with the name txtSeaarchField and txtSearchVal
and below I have a gridview
Basically, this is a enhanced search where user will choose the field name and fieldvalue and then perform search. So far, I am unable to find the best solution ..I can prepare the filterexpression string and then put in the filter expression but the point is how will I come to know that what is the type of the field ..means say ProductId is integer and what is the way to know that product id is of type int and then prepare the filter expression string accordingly. I don't want to keep this information in the array / arraylist or collection...is there anyway that I can come to know about the type of the field at runtime from gridview or objectdatasource or sqldatasource. Please reply.
Regards,
VD
|