邮箱性质--全选单选的操作和传值 用属性的name传值

封装类

using System;
using System.Collections.Generic;
using System.Web;

/// <summary>
/// Ha 的摘要说明
/// </summary>
public class Ha
{
    private string _Name;

    public string Name
    {
        get { return _Name; }
        set { _Name = value; }
    }

    private int _Age;

    public int Age
    {
        get { return _Age; }
        set { _Age = value; }
    }
}

建立方法

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Collections;

/// <summary>
/// HaData 的摘要说明
/// </summary>
public class HaData
{
    SqlConnection cnn = null;
    SqlCommand cmd = null;
    public HaData()
    {
        cnn = new SqlConnection("server=.;database=lian;user=sa;pwd=123");
        cmd = cnn.CreateCommand();
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public List<Ha> quan()
    {
        List<Ha> hlist = new List<Ha>();
        cmd.CommandText = "select * from Ha";
        cnn.Open();
        SqlDataReader ss = cmd.ExecuteReader();
        while (ss.Read())
        {

            Ha h = new Ha();
            h.Name = ss[0].ToString();
            h.Age = Convert.ToInt32(ss[1]);
            hlist.Add(h);
        }
        cnn.Close();

        return hlist;
    }
    public List<Ha> zuhecha(string sql, Hashtable h)
    {
        List<Ha> hlist = new List<Ha>();
        cmd.CommandText = sql;
        cmd.Parameters.Clear();
        foreach (string k in h.Keys)
        {
            cmd.Parameters.Add(k,h[k]);

        }
        cnn.Open();
        SqlDataReader ss = cmd.ExecuteReader();
        while (ss.Read())
        {
            Ha hh = new Ha();
            hh.Name = ss[0].ToString();
            hh.Age = Convert.ToInt32(ss[1]);
            hlist.Add(hh);

        }
        cnn.Close();
        return hlist;

    }
    public List<Ha> fenyecha(int dijiye, int meiyeshu)
    {
        List<Ha> hlist = new List<Ha>();
        cmd.CommandText = "select top "+meiyeshu+" * from Ha where Name not in (select top "+((dijiye-1)*meiyeshu)+" Name from Ha)  ";
        cnn.Open();
        SqlDataReader ss = cmd.ExecuteReader();
        while (ss.Read())
        {
            Ha h = new Ha();
            h.Name = ss[0].ToString();
            h.Age = Convert.ToInt32(ss[1]);
            hlist.Add(h);
        }
        cnn.Close();
        return hlist;
    }

    public bool delete(string name)
    {
        bool a = false;
        cmd.CommandText = "delete from  Ha where [email protected]";
        cmd.Parameters.Clear();
        cmd.Parameters.Add("@a",name);
        cnn.Open();
        try
        {
            cmd.ExecuteNonQuery();
            a = true;
        }
        catch { }

        cnn.Close();
        return a;
    }
    public bool insert(Ha h)
    {
        bool a = false;
        cmd.CommandText = "insert into Ha values(@a,@b)";
        cmd.Parameters.Clear();
        cmd.Parameters.Add("@a",h.Name);
        cmd.Parameters.Add("@b",h.Age);
        cnn.Open();
        try
        {
            cmd.ExecuteNonQuery();
            a = true;
        }
        catch { }
        cnn.Close();
        return a;

    }

}

设定样式

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table style="width:50%; text-align:center">
                    <tr style="background-color:blue; color:white">
                        <td><input type="checkbox" id="quanxuan" /><label for="quanxuan" >全选</label></td>
                        <td>姓名</td>
                        <td>年龄</td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                 <tr style="background-color:gray">
                        <td style="width:20%"><input type="checkbox" value="<%#Eval("Name") %>" class="danxuan"  name="danxuan" />单选</td>
                        <td><%#Eval("Name") %></td>
                        <td><%#Eval("Age") %></td>
                    </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

        <asp:Button ID="Button1" runat="server" Text="删除" />
    </form>
</body>
</html>
<script>
    var al = document.getElementsByClassName("danxuan");//获取所有单选数组
    document.getElementById("quanxuan").onclick = function ()//全选按钮的点击事件
    {
        for (i in al)//I返回值是al的所有索引号
        {
            al[i].checked = this.checked;//所有单选的选择状态=全选按钮的选择状态
        }
    }
    for (i in al)//给每个“单选”添加单击事件
    {

        al[i].onclick = function ()
        {
            var count = 0;//记录没有被选择的按钮的数量
            for (j in al)
            {
                if (al[j].checked == false)//如果没有被选中
                {
                    count++;//数量加1
                }
            }

            if (count == 0)
            {
                document.getElementById("quanxuan").checked = true;//如果没有被选择的按钮的数量为0,全选就被选中
            }
            else {
                document.getElementById("quanxuan").checked = false;
            }

        }

    }

</script>

设置功能  属性里的name当页面刷新时,都跳name所在位置的value值。自己需要那个就用request["name"]来接受。

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Ha h = new Ha();
        h.Name = Request["name"];//接受html页name为“name”的value值
        h.Age = Convert.ToInt32(Request["age"]);//接受html页name为“age”的value值
        bool aa = new HaData().insert(h);
        if (aa == true)
        {
            Response.Write("<script>alert(‘插入成功‘);</script>");
        }
        if (aa == false)
        {
            Response.Write("<script>alert(‘插入失败‘);</script>");
        }

        Button1.Click += Button1_Click;//删除按钮的点击事件
        if (!IsPostBack)
        {
            Repeater1.DataSource = new HaData().quan();
            Repeater1.DataBind();

        }
    }

    void Button1_Click(object sender, EventArgs e)//删除按钮的点击事件
    {
        string a = Request["danxuan"];//接收被选中框的value值(用name值)
        if (a == "")
        { }
        else
        {
            string[] name = a.Split(‘,‘);//将名字分成数组
            string shiname = "";
            string chengname = "";
            for (int i = 0; i < name.Length; i++)
            {
                bool b = new HaData().delete(name[i]);
                if (b)
                {

                    chengname += name[i]+"  ";
                }
                else
                {
                    shiname = name[i] + "  ";
                }
            }

            Response.Write("<script>alert(‘删除成功有" + chengname + ",删除失败的有" + shiname + "‘);</script>");
            Repeater1.DataSource = new HaData().quan();//重新绑定数据源
            Repeater1.DataBind();

        }
    }
}

纯html添加功能  (form中method为用什么方式进行提交,action为将数据提交到哪里去)

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form action="Default.aspx" method="post">//method为用什么方式进行提交,action为将数据提交到哪里去
    姓名:<input type="text" name="name" /><br />
    年龄:<input type="text" name="age" id="age" />
    <input type="submit" value="提交添加" />
    </form>
</body>
</html>
<script>
    var age = document.getElementById("age");
    age.onkeyup = function ()//限定数字
    {
        if (isNaN(age.value.trim()))
        {
            this.value = this.value.trim().substr(0, this.value.trim().length-1);
        }

    }

</script>

完!!

时间: 2024-08-11 03:29:33

邮箱性质--全选单选的操作和传值 用属性的name传值的相关文章

checkbox 全选 单选的使用

绑定数据 if (!IsPostBack) { using (UsersDataContext con = new UsersDataContext()) { Repeater1.DataSource = con.Users.ToList(); Repeater1.DataBind(); } } 后台 checkbox 选中状态 去的值 void Button1_Click(object sender, EventArgs e) { Label1.Text=Request["ck"];

Jquery全选单选功能

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="wzgyd.WebForm5" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/x

4.1邮箱的全选,全不选,反选

事件:onclick 属性:checked 对于分清getElementsByTagName('元素名')里的元素名, 可以先提取其外面一层的元素,再在此基础上用getElementsByTagName('元素名') 用到for语句,if语句,length <!DOCTYPE html><html><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible&q

全选 单选 控件的判断

checkbox和radio 这两个控件比较的特殊 如果我们想对是否选中的控件进行判断 并提示要选择的项,那我们得如何来做呢 <form name="form" id="form"> <input type="checkbox" name="sex" value="男">男 <input type="checkbox" name="sex"

jQuery 表单应用:全选/取消全选,表单验证,网页选项卡切换

应用一:单行文本框应用 需要用到的 API focus([[data],fn])   --> 当元素获得焦点时,触发 focus 事件 blur([[data],fn])     --> 当元素失去焦点时,触发 blur 事件 <!DOCTYPE html> <html> <head lang="en">     <meta charset="UTF-8">     <title></ti

jQuery全选反选插件的写法

jQuery全选反选插件,经易让你实现一个表单列表数据的全选与取消全选功能,内含示例,小巧实用.自动判断当前选中数量,加上全选.在没有jQuery之前,我们需要一大段js代码来实现这种效果.有了jQuery这个强大的库之后,我们可以很方便的开发实现这种效果的jQuery插件.我将它命名为jQuery.fn.check插件.前端框架分享 在构建我们的插件之前,我们想考虑一下其功能需求: 所有复选框的状态都随全选复选框的状态而发生变化:如果所有复选框都被选中时,全选复选框立即处于选中状态:如果当前选

页面中公用的全选按钮,单选按钮组件的编写

相应的js代码为: var checkAll = $("[data-checkbox-checkall]"); //遍历处理每一组的情况 checkAll.each(function(){ var groupName = $(this).attr("data-checkbox-group"); startCheck(groupName); }); function startCheck(groupName){ //所有的该组元素 var allCheckbox =

JS全选

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html>    <head>        <script type="text/javascript" src="jquery-1.8.3.min.js"></script>        <scri

vue中使用计算属性巧妙的实现多选框的“全选”

接下来我会以一个购物车的例子,来演示如果借助计算属性,精巧的实现多选框的全选功能.当然,有全选,自然对应的也还有取消全选. 以下这张gif图,就是最终的实现效果: 第一步,针对购物车每一个商品进行设置 根据上图可以发现,购物车中的每一件商品都有一个选择框,而这个选择框则是需要用一个布尔字段,通过v-model绑定进去,监听该条购物车记录的选中状态. 首先,沟通后端,为前端预留一个select属性 该属性默认设置为false,因为购物车在被渲染出来时,默认是应该没有勾选任何一件商品的 然后,绑定到