Visual Studio .NET 2002.NET 1.0Visual Studio .NET 2003.NET 1.1中级开发Visual StudioJavascriptWindows.NETVisual BasicASP.NET
适用于 ASP.NET 的可筛选网格






3.67/5 (6投票s)
一篇关于 ASP.NET 可筛选网格的文章。
引言
本文介绍了一个具有基于列值筛选功能的 ASP.NET DataGrid
。
详细说明
我尽量保持代码简洁。此代码使用 JavaScript 方法 filtergrid
构建 URL 的 QueryString。数据源根据 QueryString 值进行筛选。
// 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;
}
在代码隐藏文件中,FillDataGridColumns
方法使用 HTML 文本框和按钮创建列标题。
'// 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
进一步开发范围
- 目前,此控件仅处理
String
和Double
数据类型。可以修改它以处理其他数据类型。 - 筛选仅适用于单个值,无法搜索多个值。
欢迎提出您的建议和意见。
结论
基本 JavaScript 和代码隐藏文件的使用有助于增强 DataGrid
控件的功能。