Vous êtes sur la page 1sur 6

Csharp Asp.

Net Articles C# VB Tutorials Code Examples Samples


ASP.NET,C#,VB,SharePoint,AJAX,SQL, GridView ,jQuery,MVC,WCF,WPF

HOME AJAX ASP.NET C# CRYSTAL REPORTS GRIDVIEW JAVASCRIPTS JQUERY SHAREPOINT 2010 SQL SERVER VB.NET WINDOWS FORMS

GridView Filter Expression With DropDownList ASP.NET


Posted by amiT jaiN This example explains how to Filter GridView With DropDownList In ASP.NET Using FilterExpression And Filter Paramaters Or GridView Filtering with Sql Server And SqlDataSource. I m using northwind database and customers table to show data and filter gridview with dropdownlist. First of all open aspx page in design view and place 2 dropdownlist, 1 gridview and 3 SqlDatasource on the page. Configure all 3 sqldatasources as according to code mentioned below. and use them for datasource to populate city dropdown, country dropdown and gridview. You can also read ModalPopUp extender in Gridview to know how to configure SqlDataSource.
Like

Search

+66 Recommend this on Google

1,461 people like this.

Follow @dotnetfreak

395 follow ers

We're on

Follow

Subscribe by E-mail
Subscribe

HTML Markup to Populate Dropdowns

<s:rponitI=dliy rnt"evr apDoDwLs D"dCt" ua=sre" ApnDtBudtm=Tu" pedaaonIes"re AtPsBc=Tu" uootak"re DtSucI=slaaoreiy aaoreD"qDtSucCt" DtTxFed"iy aaetil=Ct" DtVleil=Ct"Wdh"0p" aaauFed"iy it=10x> <s:ittmVle""Al/s:ittm apLsIe au=%>l<apLsIe> <apDoDwLs> /s:rponit <s:qDtSuc I=slaaoreiy rnt"evr apSlaaore D"qDtSucCt" ua=sre" CnetoSrn=<$CnetoSrnsnrhidoncintig%" oncintig"% oncintig:otWnCnetoSrn > SlcCmad"EETDSIC Ct FO Csoes> eetomn=SLC ITNT iy RM utmr" <apSlaaore /s:qDtSuc>

Recent Posts
Populate Bind DropDownList From XML File In Asp.Net Auto Refresh Update GridView In Asp.Net Ajax With Timer SharePoint 2010 Custom Login Page For FBA Select GridView Row Without Postback OnClick Of Cell JavaScript Forms Based Authentication FBA In SharePoint 2010 Claims Loading...

<s:rponitI=dlonr"rnt"evr apDoDwLs D"dCuty ua=sre" ApnDtBudtm=Tu" pedaaonIes"re AtPsBc=Tu" uootak"re DtSucI=slaaoreonr" aaoreD"qDtSucCuty DtTxFed"onr" aaetil=Cuty DtVleil=Cuty Wdh"0p" aaauFed"onr" it=10x> <s:ittmVle""Al/s:ittm apLsIe au=%>l<apLsIe> <apDoDwLs> /s:rponit

Find More Articles

Search
<s:qDtSuc I=slaaoreonr"rnt"evr apSlaaore D"qDtSucCuty ua=sre" CnetoSrn=<$CnetoSrnsnrhidoncintig%" oncintig"% oncintig:otWnCnetoSrn > SlcCmad"EETDSIC [onr]FO [utmr]> eetomn=SLC ITNT Cuty RM Csoes" <apSlaaore /s:qDtSuc>

Now Configure third sqldatasource to populate gridview based on filter expression as mentioned below

HTML markup of gridview and sqldatasource with filter expression

<s:rdiwI=GiVe1 rnt"evr apGiVe D"rdiw" ua=sre"

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

1/6

Alwaig"re loPgn=Tu" DtSucI=slaaorerdiw aaoreD"qDtSucGiVe" AtGnrtClms"as" uoeeaeoun=Fle Csls=GiVeSye sCas"rdiwtl" GiLns"oe Wdh"5p" rdie=Nn" it=60x SoHae=fle> hwedr"as" <oun> Clms <s:onFedDtFed"utmrD HaeTx=Csoe I"> apBudil aail=CsoeI" edret"utmr D/ <s:onFedDtFed"opnNm"HaeTx=Cmay/ apBudil aail=Cmayae edret"opn"> <s:onFedDtFed"otcNm"HaeTx=Nm"> apBudil aail=Cnatae edret"ae/ <s:onFedDtFed"iy HaeTx=ct"> apBudil aail=Ct" edret"iy/ <s:onFedDtFed"onr"HaeTx=Cuty/ apBudil aail=Cuty edret"onr"> <Clms /oun> <apGiVe> /s:rdiw

<s:qDtSuc I=slaaorerdiw apSlaaore D"qDtSucGiVe" rnt"evr ua=sre" CnetoSrn=<$CnetoSrnsnrhidoncintig%" oncintig"% oncintig:otWnCnetoSrn > SlcCmad"EET[utmrD,[opnNm] [otcNm] eetomn=SLC CsoeI] Cmayae, Cnatae, [iy,[onr]FO [utmr] Ct] Cuty RM Csoes" FleEpeso=[iy lk '0% ad[onr]lk '1%" itrxrsin"Ct] ie {}' n Cuty ie {}'> <itraaees FlePrmtr> <s:otoPrmtrCnrlD"dCt"Nm=Ct" apCnrlaaee otoI=dliy ae"iy PoetNm=SlceVle rpryae"eetdau" Tp=Srn"/ ye"tig > <s:otoPrmtrCnrlD"dCuty Nm=Cuty apCnrlaaee otoI=dlonr" ae"onr" PoetNm=SlceVle rpryae"eetdau" Tp=Srn"/ ye"tig > <FlePrmtr> /itraaees <apSlaaore /s:qDtSuc>

Build and run the application.

Download Sample Code


OTHER POSTS ON ASP.NET C# VB.NET Detect Browser Refresh to avoid events fired again in ASP.NET Search Records In GridView And Highlight Results Using AJAX ASP.NET ASP.NET Submit form on Enter Key Default submit Button Register Dlls Assembly Custom Controls User Control Ascx In Web.Config ASP.NET ASP.NET Search records in GridView footer and highlight results using Ajax User validation authentication using session in ASP.NET

Tw eet

+3 Recommend this on Google

Like

50 people like this.

Follow @dotnetfreak

395 follow ers

We're on

Follow

If you like this post than join us or share

Labels: ASP.NET, DropDownList, GridView

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

2/6

10 COMMENTS:

Mindy and Marty said... I left a comment on your post in 2009 about a code for page views on your blog. Can you see my question about how to reset the page views for each post I make so it starts the count at zero again. I tried removing it and doing a whole new one but it just picks right back up where it left off. How can I reset the count?>! thanks! my blog is mindymarty.blogspot.com

April 10, 2011 5:17 AM

kvministries said... Hi, I got the code from your blog. But I am also with the same question, even I do not know the trick.

July 3, 2011 9:06 AM

shiko said... can u writ co C#

August 17, 2011 2:14 PM

Anonymous said... thanks !

August 24, 2011 6:05 PM

comment system said... Very well written post ! I just tried the above given code and it worked great. Thank a lot. You saved my couple of hours :))

October 31, 2011 4:55 PM

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

3/6

sameer said... hi i have dropdownlist, i binding the data in the dropdown list, my problem is , how to set default value is NULL ?

January 13, 2012 12:27 AM

Anonymous said... Cannot perform 'Like' operation on System.Decimal and System.String. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.EvaluateException: Cannot perform 'Like' operation on System.Decimal and System.String. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:

[EvaluateException: Cannot perform 'Like' operation on System.Decimal and System.String.] System.Data.LikeNode.Eval(DataRow row, DataRowVersion version) +475 System.Data.BinaryNode.EvalBinaryOp(Int32 op, ExpressionNode left, ExpressionNode right, DataRow row, DataRowVersion version, Int32[] recordNos) +12138 System.Data.BinaryNode.Eval(DataRow row, DataRowVersion version) +29 System.Data.DataExpression.Invoke(DataRow row, DataRowVersion version) +151 System.Data.Index.AcceptRecord(Int32 record, IFilter filter) +103 System.Data.Index.InitRecords(IFilter filter) +303 System.Data.Index..ctor(DataTable table, Int32[] ndexDesc, IndexField[] indexFields, Comparison`1 comparison, DataViewRowState recordStates, IFilter rowFilter) +491 System.Data.DataTable.GetIndex(IndexField[] indexDesc, DataViewRowState recordStates, IFilter rowFilter) +228 System.Data.DataView.UpdateIndex(Boolean force, Boolean fireEvent) +165 System.Data.DataView.UpdateIndex(Boolean force) +12 System.Data.DataView.SetIndex2(String newSort, DataViewRowState newRowStates, IFilter newRowFilter, Boolean fireEvent) +113 System.Data.DataView.SetIndex(String newSort, DataViewRowState newRowStates, IFilter newRowFilter) +17 System.Data.DataView.set_RowFilter(String value) +160 System.Web.UI.WebControls.FilteredDataSetHelper.CreateFilteredDataView(DataT able table, String sortExpression, String filterExpression, IDictionary filterParameters) +396 System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelect Arguments arguments) +2012 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

4/6

System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Control.PreRenderRecursiveInternal() +175 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225

January 28, 2012 11:00 PM

Anonymous said... hi i have a praticular problem actually the problem is that i have a grid having some data in it and i want my grid to be filter with text box i mean to say when i enter some text in textbox so grid should only show the relevant data. .

February 14, 2012 2:54 PM

amiT jaiN said...

@Above: You can change dropdownlists to textbox and propertyname to text in filterparameters Check this sample code

February 15, 2012 6:47 PM

Anonymous said... Do you have the stylesheet.css that goes with this project? Thanks!

10

August 1, 2012 12:44 AM

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

5/6

Post a Comment

LINKS TO THIS POST


Create a Link Post a Comment Click here if you are facing problem in writing comment..

Etryu cmet. ne or omn..

Comment as: Google Account Publish Preview

Newer Post Subscribe to: Post Comments (Atom)

Home

Older Post

Copyright 2008-2012 csharpdotnetfreak.blogspot.com. All Rights Reserved. The content is copyrighted to Amit Jain and may not be reproduced on other w ebsites w ithout permission from the ow ner. w ebsites copying content w ill be reported to their w eb host w ith a DMCA take dow n notice.

HOME

MY HOME PAGE

csharpdotnetfreak.blogspot.com/2011/04/gridview-filterexpression-dropdownlist.html

6/6

Vous aimerez peut-être aussi