Click here to Skip to main content
Licence 
First Posted 12 Aug 2004
Views 66,538
Bookmarked 41 times

Filterable Grid for ASP.NET

By | 12 Aug 2004 | Article
An article on a filterable Grid for ASP.NET.

Sample Image

Introduction

This article presents an ASP.NET DataGrid with ability to filter based on column values.

Details

I tried to keep the code simple. This code uses JavaScript method filtergrid to build QueryString for the URL. The datasource is filtered based on QueryString values.

 // this method sets the filter condition.
function filtergrid(columnname)
{
  var val;
  var baseurl;
  
  // I have set the baseurl of the demo page here.
  // You can simply replace it with your .aspx page name
  // or may be read programmatically
  // to make this control generic.
  baseurl = 'FilterGridPage.aspx';
  val = document.getElementById('txt' + columnname).value;
  
  self.location.href = baseurl + '?selectedcolumn=' 
                   + columnname + '&selectedvalue=' + val;
}

In the code-behind file, the FillDataGridColumns method creates the column headers with HTML textbox and button.

   '// header cell code
   headerhtml = DisplayNames(i)
   
   '// create html text
   headerhtml = headerhtml & " <br> " & " & _
   "<Input type=text class=FilterTextBox id=txt" & ColumnNames(i) & " /> " & _
   "<Input class=ButtonStyle type=button id=btn" & ColumnNames(i) & _
   " onclick=""javascript:filtergrid('" & ColumnNames(i) & "');"" value='Go'/>"
   
   '// simply set the html text as HeaderText property of BoundColumn
   <BoundColumnVariable>.HeaderText = headerhtml

Scope of further development

  • At present, this control handles String and Double datatypes only. It can be modified to handle other datatypes.
  • Filter works on single value only and can not search for multiple values.

All your suggestions and comments are welcome.

Conclusion

The use of basic JavaScript and code-behind file helps to enhance the functionality of the DataGrid control.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Hemang Shukla

Software Developer (Senior)
NAB
Australia Australia

Member

Hemang Shukla is Senior Analyst Programmer at National Australia Bank. His main area of interest are ASP.Net, VB.Net, C#, Sharepoint, .Net Web Services & C++.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalthe baseurl Pinmemberzxd991517:01 13 Oct '08  
GeneralA More Generic method Pinmemberchuck the coder1:35 12 Apr '05  
GeneralRe: A More Generic method Pinmemberkvc9:57 23 Apr '05  
GeneralRe: A More Generic method Pinmemberchuck the coder4:47 26 Apr '05  
GeneralEfficient filter !!!!! PinmemberSukim7:59 21 Aug '04  
GeneralRemove filter PinmemberSébastien Lorion12:49 18 Aug '04  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120528.1 | Last Updated 13 Aug 2004
Article Copyright 2004 by Hemang Shukla
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid