Table中筛选数据

 前台页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        table
        {
            border: 0;
            border-collapse: collapse;
        }
        div
        {
            font: normal 12px/17px Arial;
        }
        td
        {
            font: normal 12px/17px Arial;
            padding: 2px;
            width: 100px;
        }
        th
        {
            font: bold 12px/17px Arial;
            text-align: left;
            padding: 4px;
            border-bottom: 1px solid #333;
            width: 100px;
        }
        .even
        {
            background: #FFF38F;
        }
        /* 偶数行样式*/.odd
        {
            background: #FFFFEE;
        }
        /* 奇数行样式*/.selected
        {
            background: #FF6500;
            color: #fff;
        }
    </style>

    <script src="JS/jquery-1.3.2.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function() {
            $("tbody>tr:odd").addClass("odd");
            $("tbody>tr:even").addClass("even");
            $("tbody>tr").click(function() {
                var tid = $(this).attr("id");
                alert(tid);

            });
            //文本框添加keyup事件
            $("#filterName").keyup(function() {
                //隐藏所有的tr
                $("table tbody tr")
    .hide()
                //过滤掉和输入内容不匹配的tr
    .filter(":contains('" + ($(this).val()) + "')")
    .show();
            });
        })
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        筛选:
        <input id="filterName" type="text" />
        <br />
        <table id="tab1">
            <thead>
                <tr>
                    <th>
                        姓名
                    </th>
                    <th>
                        性别
                    </th>
                    <th>
                        暂住地
                    </th>
                </tr>
            </thead>
            <tbody style="cursor: pointer">
                <%for (int i = 0; i < GetAll().Rows.Count; i++)
                  {%>
                <tr id='<%=GetAll().Rows[i]["uid"] %>'>
                    <td>
                        <%=GetAll().Rows[i]["uname"] %>
                    </td>
                    <td>
                        <%=GetAll().Rows[i]["sex"] %>
                    </td>
                    <td>
                        <%=GetAll().Rows[i]["address"] %>
                    </td>
                </tr>
                <%} %>
            </tbody>
        </table>
    </div>
    </form>
</body>
</html>
后台代码:
public DataTable GetAll()
        {
            SqlConnection conn = new SqlConnection("server=.;database=Example;uid=sa;pwd=***");
            string sql = "select *from userinfo";
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];

        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值