封装类

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[].ToString();
h.Age = Convert.ToInt32(ss[]);
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[].ToString();
hh.Age = Convert.ToInt32(ss[]);
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-)*meiyeshu)+" Name from Ha) ";
cnn.Open();
SqlDataReader ss = cmd.ExecuteReader();
while (ss.Read())
{
Ha h = new Ha();
h.Name = ss[].ToString();
h.Age = Convert.ToInt32(ss[]);
hlist.Add(h);
}
cnn.Close();
return hlist;
} public bool delete(string name)
{
bool a = false;
cmd.CommandText = "delete from Ha where Name=@a";
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 = ;//记录没有被选择的按钮的数量
for (j in al)
{
if (al[j].checked == false)//如果没有被选中
{
count++;//数量加1
}
} if (count == )
{
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 = ; 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(, this.value.trim().length-);
} } </script>

完!!

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

  1. vue开发购物车,解决全选单选问题

    实现全选单选,在vue中无法通过this获取input中的checkbox的checked属性,但是可以通过vue对input的特殊方式v-model来实现对应数据的绑定,同样也可以通过这种方式实现购 ...

  2. vue-实现全选单选

    在获取列表页面数据时,通过forEach遍历存储数据的对象,给对象中添加一个selected变量,值为布尔值. 点击全选时,通过遍历将对象中selected的布尔值改变 点击单选时,被点中的通过筛选加 ...

  3. checkbox 全选 单选的使用

    绑定数据 if (!IsPostBack) { using (UsersDataContext con = new UsersDataContext()) { Repeater1.DataSource ...

  4. element-ui 里面el-checkbox多选框,实现全选单选

    data里面定义了 data:[],        actionids:[],//选择的那个actionid        num1:0,//没选择的计数        num2:0,//选中的计数  ...

  5. Jquery全选单选功能

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx. ...

  6. jq 操作表单中 checkbox 全选 单选

    知识点: Note: 1: .prop() 和 .attr() 方法的区别 .prop() 针对标签既有属性 .attr() 针对自定义属性 2: $('input:checked')即为选中元素. ...

  7. DataGrid列中加入CheckBox 全选 点击Header全选 和 只操作选中部分 功能的实现

    先写个效果 中午接着写 反正没人看 只是给自己记录

  8. jQuery中表单的常用操作(全选、反选)

    表单的全选.反选操作一 <form method="post" action=""> 你爱好的运动是?<input type="ch ...

  9. js实现表单checkbox的单选,全选

    全选&单选 //<input type="checkbox" name="" class="quan" value=" ...

随机推荐

  1. PHP中9大缓存技术总结(转载 http://www.php100.com/html/php/lei/2015/0919/8969.html)

    PHP中9大缓存技术总结 来源:   时间:2015-09-19 02:40:33   阅读数:57767 分享到: 12 [导读] 1.全页面静态化缓存也就是将页面全部生成html静态页面,用户访问 ...

  2. oracle的散列聚簇表

    在簇表中,Oracle使用存储在索引中的键值来定位表中的行, 而在散列聚簇表中,使用了散列函数代替了簇索引,先通过内部函数或者自定义的函数进行散列计算,然后再将计算得到的码值用于定位表中的行. 创建散 ...

  3. fnd_profile.value('AFLOG_ENABLED')的取值 和配置文件相关SQL

    SELECT * FROM FND_PROFILE_OPTIONS_VL TT WHERE TT.PROFILE_OPTION_NAME LIKE '%AFLOG%' FND:启用调试日志 详细的参考 ...

  4. PAT乙级 1031. 查验身份证(15) 标志要清零!!!!!!!!!

    1031. 查验身份证(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 一个合法的身份证号码由17位地区. ...

  5. TP主从服务器配置

    在config.php文件中,设置‘DB_DEPLOY_TYPE’=>1,‘DB_HOST’=>‘localhost,192.168.0.1,192.168.0.23’,各个主机之间用逗号 ...

  6. 《Focus On 3D Terrain Programming》中一段代码的注释一

    取自<Focus On 3D Terrain Programming>中的一段: //--------------------------------------------------- ...

  7. cvCreateImage函数说明(转载)

    cvCreateImage是openCV中的一个函数.OpenCV是Intel公司支持的开源计算机视觉库. cvCreateImage:创建首地址并分配存储空间    IplImage* cvCrea ...

  8. 为什么super()和this()调用语句不能同时在一个构造函数中出现的解释

    我想这应该是Java构造函数的一种机制吧,首先以子类和父类为例.当你创建一个子类的实例时,首先会调用父类的构造函数,然后再调用子类的构造函数,如果父类中没有缺省构造函数,则必须再子类的构造函数中显示的 ...

  9. Understanding the RelationshipType Enumeration [AX 2012]

    Understanding the RelationshipType Enumeration [AX 2012] 3 out of 3 rated this helpful - Rate this t ...

  10. 苹果app审核的规则总结

    1.1为App Store开发程序,开发者必须遵守 Program License Agreement (PLA).人机交互指南(HIG)以及开发者和苹果签订的任何协议和合同.以下规则和示例旨在帮助开 ...