前台代码:

    <div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True">
<asp:ListItem Text="Sunny" Value="Sunny"></asp:ListItem>
<asp:ListItem Text="Mike" Value="Mike"></asp:ListItem>
<asp:ListItem Text="Jakes" Value="Ken"></asp:ListItem>
<asp:ListItem Text="Ken" Value="Ken"></asp:ListItem>
</asp:CheckBoxList>
<hr />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("City") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>

后台代码:

protected void Page_Load(object sender, EventArgs e)
{
string strwhere = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
strwhere += "'" + item.Value.ToString() + "',";
}
}
BindGridView(strwhere);
}
public void BindGridView(string Names)
{
DataTable dt=new DataTable();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DemosDatabaseConnectionString"].ConnectionString))
{
conn.Open();
if (Names.Length <= )
{
string sql = "select * from Customers";
SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
sda.Fill(dt); GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
string sql = "select * from Customers where Name in (" + Names.Substring(, Names.Length - ) + ")";
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
sda.Fill(dt); GridView1.DataSource = dt;
GridView1.DataBind();
}
} }

http://forums.asp.net/t/2042553.aspx

根据选择项过滤GridView的更多相关文章

  1. Js获取下拉框当前选择项的文本和值

    现在有一个Id为AreaId的下拉框,要获取它当前选择项的文本和值有以下方法: <span class="red">* </span> 地       区: ...

  2. Chosen中选择项的更新

    Chosen 选择项的动态修改/更新 如果你需要去动态更新select选择框里的选择项,你需要通知Chosen去响应这个变动,你需要在这个选项框是触发一个"liszt:updated&quo ...

  3. iOS开发——UI篇&下拉弹出列表选择项效果

    下拉弹出列表选择项效果 右边菜单中的按键,点击弹出一个列表可选择,选择其中一个,响应相应的事件并把文字显示在右边的菜单上:弹出下拉效果使用LMDropdownView插件,可以用POD进行加载pod  ...

  4. C# winform 选择项 省市连动

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  5. 如何实现select组件的选择输入过滤作用

    实现select组件的选择输入过滤作用的js代码如下: /** *其中//******之间的部分显示的是在没有选择输入过滤功能的代码上加入的功能代码 ** / (function ( $ ) { $. ...

  6. selenium 定位input输入框下的选择项

    今天的问题与下图中的类似 这是一个input型输入框,当我点击或输入值时,输入框下方会显示选择项帮助快速输入,代码如下: <input class="v-input some" ...

  7. CentOS6.9-zabbix3.2启动失败原因及页面没有mysql选择项

     环境内核信息: [root@zabbix- ~]# uname -a Linux lodboyedu- -.el6.x86_64 # SMP Tue Mar :: UTC x86_64 x86_64 ...

  8. WPF中使用后台代码来控制TreeView的选择项(SelectedItem)以及展开节点操作

    首先为TreeView控件制作一个Style: <Style x:Key="LibraryTreeViewItemStyle" TargetType="{x:Typ ...

  9. springMVC 复选框带有选择项记忆功能的处理

    前言:由于jsp管理页面经常会遇到复选框提交到JAVA后台,后台处理逻辑完成后又返回到jsp页面,此时需要记住jsp页面提交时复选框的选择状态,故编写此功能! 一.复选框的初始化 1.1.jsp页面 ...

随机推荐

  1. PHP用户登录与注册页面

    PHP用户登录模块实现 项目包含的功能脚本: login.php//登录 reg.php//注册用户 user_add.php//注册校验脚本 user_login_check.php//登录校验脚本 ...

  2. 尼康D5100使用设置及技巧,同样也适用尼康D5200

    尼康D5100使用设置及技巧,同样也适用尼康D5200,希望对新手能有点帮助. 一.设置 1.优化校准:可以在menu菜单中找到它,一般使用"标准"就可以,建议将"标准& ...

  3. python 常用模块及方法

    ******************** PY核心模块方法 ******************** os模块: os.remove()         删除文件 os.unlink()        ...

  4. python+sublime text2中文乱码[Decode error - output not utf-8]

    转自: http://blog.sina.com.cn/s/blog_765abd7b0101dtbw.html 学习,记录一下.中文编码真的挺麻烦.抽空把自己的sb3的配置写一些. 该问题让我纠结了 ...

  5. gitlab使用入门

    第一步:安装git软件 方法:百度git 点击下载,然后双击安装,一直点下一步即可.   第二步:设置用户名和邮箱 方法:在桌面上点鼠标右键,选择Git Bash,然后分别运行命令 git confi ...

  6. 四种常见的提示弹出框(success,warning,error,loading)原生JavaScript和jQuery分别实现

    原文:四种常见的提示弹出框(success,warning,error,loading)原生JavaScript和jQuery分别实现 虽然说现在官方的自带插件已经有很多了,但是有时候往往不能满足我们 ...

  7. 《windows程序设计》学习_3.3:利用xp扫雷资源

    #include<windows.h> #include "resource.h" LRESULT CALLBACK WndProc (HWND, UINT, WPAR ...

  8. 【Perl学习笔记】2. perl中的bless理解

    bless有两个参数:对象的引用.类的名称. 类的名称是一个字符串,代表了类的类型信息,这是理解bless的关键. 所谓bless就是把 类型信息 赋予 实例变量. 程序包括5个文件:person.p ...

  9. AppStore被拒原因及总结

    4.5 - Apps using background location services must provide a reason that clarifies the purpose of th ...

  10. TCP状态转换机说明

    建立一个 TCP 连接TCP 是一个面向连接的协议,无论哪一方向另一方发送数据之前,都必须先在双方之间建立一条连接.本节将详细讨论一个TCP 连接是如何建立的以及通信结束后是如何终止的. TCP使用三 ...