c# - How to apply a filter expression to a gridview? -
i have grid view , filter expression database. want apply filter expression grid data grid sort. column criteria match column of grid. isn't problem.
i can set grid.filterexpression = filter
, how can sort values grid filter criteria?
code: html markup populate dropdowns
<asp:sqldatasource id="sqldatasourcecity" runat="server" connectionstring="<%$ connectionstrings:northwindconnectionstring %>" selectcommand="select distinct city customers"> </asp:sqldatasource> <asp:dropdownlist id="ddlcountry" runat="server" appenddatabounditems="true" autopostback="true" datasourceid="sqldatasourcecountry" datatextfield="country" datavaluefield="country" width="100px"> <asp:listitem value="%">all</asp:listitem> </asp:dropdownlist> <asp:sqldatasource id="sqldatasourcecountry" runat="server" connectionstring="<%$ connectionstrings:northwindconnectionstring %>" selectcommand="select distinct [country] [customers]">
html markup of gridview , sqldatasource filter expression
<asp:gridview id="gridview1" runat="server" allowpaging="true" datasourceid="sqldatasourcegridview" autogeneratecolumns="false" cssclass="gridviewstyle" gridlines="none" width="650px" showheader="false"> <columns> <asp:boundfield datafield="customerid" headertext="customer id"/> <asp:boundfield datafield="companyname" headertext="company"/> <asp:boundfield datafield="contactname" headertext="name"/> <asp:boundfield datafield="city" headertext="city"/> <asp:boundfield datafield="country" headertext="country"/> </columns> </asp:gridview> <asp:sqldatasource id="sqldatasourcegridview" runat="server" connectionstring="<%$ connectionstrings:northwindconnectionstring %>" selectcommand="select [customerid], [companyname], [contactname], [city], [country] [customers]" filterexpression="[city] '{0}%' , [country] '{1}%'"> <filterparameters> <asp:controlparameter controlid="ddlcity" name="city" propertyname="selectedvalue" type="string" /> <asp:controlparameter controlid="ddlcountry" name="country" propertyname="selectedvalue" type="string" /> </filterparameters> </asp:sqldatasource>
source :-http://csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html
Comments
Post a Comment