Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filtering gridview not working

Status
Not open for further replies.

newbieAl

Programmer
Sep 10, 2007
21
US
I have two drop down lists to use as a filter for a gridview. This is what the select command in the gridview's datasource looks like:

SelectCommand="SELECT * FROM [datatable] WHERE ([afield] = @afield) OR ([bfield] = @bfield) ">
<selectparameters>

Type="String" />

Type="String" />
</selectparameters>

The filtering is not working for the second control. Bfield does not filter the data.
 
Can you please provide all of the code for this functionality so we can better assist you?

Thanks :)
 
Dropdown lists:

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" >
<asp:ListItem>Select an item</asp:ListItem>
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
</asp:DropDownList><br /><br />

<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True">
<asp:ListItem>Select an item</asp:ListItem>
<asp:ListItem>Closed</asp:ListItem>
<asp:ListItem>Open</asp:ListItem>
</asp:DropDownList>


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If DropDownList1.SelectedIndex.Equals(0) Then
datatable.SelectCommand = ("SELECT * FROM
")
GridView1.DataBind()

End If

End Sub
 
My suggestions:
Get away from the datasource controls. They cause too many issues once you get away from a simple query.
Write stored procedures. They are quicker, reuseable and easily maintained.
 
Thank you, you are correct and that is my plan to move to sp's however what I am encountering is a filtering issue and would need assistance with that.
 
Here is my sqldatasource info (I noticed it didn't post properly the first time):

SelectCommand="SELECT * FROM [datatable] WHERE ([afield] = @afield) OR ([bfield] = @bfield) ">

SelectParameters
ControlParameter ControlID="DropDownList1" Name="afield" PropertyName="SelectedValue" Type="String" />
ControlParameter ControlID="DropDownList2" Name="bfield" PropertyName="SelectedValue" Type="String" />
SelectParameters>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top