摘要:aspx页:代码如下: <script src="Jquery1.7.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('#Checkbox1').click(function () { if ($('#Checkbox1').is(':checked')) { $('td input').attr('checked', true); } else { $('td input').attr('checked', false); } }) $('#Checkbox2').click(function () { $('td input').each(function () { $(this).attr('checked', !$(this).attr('checked')) }) }) }) </script> </head> <body> <form id="form1" runat="server"> <p> <input id="Checkbox1" type="checkbox" />全选<input id="Checkbox2" type="checkbox" />反选<asp:Button ID="Button1" runat="server" Text="删除" onclick="Button1_Click" /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:TemplateField HeaderText="选择"> <ItemTemplate> <asp:CheckBox ID="CheckBox3" runat="server" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Id" HeaderText="编号" /> <asp:BoundField DataField="NewsTitle" HeaderText="标题" /> <asp:BoundField DataField="NewsContent" HeaderText="新闻内容"> <ItemStyle Width="200px" /> </asp:BoundField> <asp:BoundField DataField="NewsCreator" HeaderText="创建者" /> <asp:BoundField DataField="CreateTime" HeaderText="创建时间" /> </Columns> </asp:GridView> </p> </form>

小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

aspx页

代码如下:

<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#Checkbox1').click(function () {
if ($('#Checkbox1').is(':checked')) {
$('td input').attr('checked', true);
}
else { $('td input').attr('checked', false); }
})
$('#Checkbox2').click(function () {
$('td input').each(function () {
$(this).attr('checked', !$(this).attr('checked'))
})
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
<input id="Checkbox1" type="checkbox" />全选<input id="Checkbox2" type="checkbox" />反选<asp:Button
ID="Button1" runat="server" Text="删除" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="编号" />
<asp:BoundField DataField="NewsTitle" HeaderText="标题" />
<asp:BoundField DataField="NewsContent" HeaderText="新闻内容">
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="NewsCreator" HeaderText="创建者" />
<asp:BoundField DataField="CreateTime" HeaderText="创建时间" />
</Columns>
</asp:GridView>
</p>
</form>

后台cs文件

代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load();
}
}
private void load()//就实现绑定
{
Jquery三层实现删除功能.Model.T_News mm = new Model.T_News();
Jquery三层实现删除功能.BLL.T_News bb = new BLL.T_News();
string sqlwhere = "Id<25";
ds = bb.GetList(sqlwhere);//获取dataset绑定
this.GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//遍历每一行
foreach (GridViewRow item in GridView1.Rows)//一定要记住这里是gridviewrow不是datarow
{
CheckBox cb = (CheckBox)item.FindControl("CheckBox3");//找到这个选中项
if (cb.Checked)//选中
{
Jquery三层实现删除功能.BLL.T_News bb = new BLL.T_News();
if (bb.DeleteList(item.Cells[1].Text))//调用bb.DeleteList(id)删除
{
Response.Write("删除成功");
}
load();

aspx页

代码如下:

<script src="Jquery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#Checkbox1').click(function () {
if ($('#Checkbox1').is(':checked')) {
$('td input').attr('checked', true);
}
else { $('td input').attr('checked', false); }
})
$('#Checkbox2').click(function () {
$('td input').each(function () {
$(this).attr('checked', !$(this).attr('checked'))
})
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<p>
<input id="Checkbox1" type="checkbox" />全选<input id="Checkbox2" type="checkbox" />反选<asp:Button
ID="Button1" runat="server" Text="删除" onclick="Button1_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="选择">
<ItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Id" HeaderText="编号" />
<asp:BoundField DataField="NewsTitle" HeaderText="标题" />
<asp:BoundField DataField="NewsContent" HeaderText="新闻内容">
<ItemStyle Width="200px" />
</asp:BoundField>
<asp:BoundField DataField="NewsCreator" HeaderText="创建者" />
<asp:BoundField DataField="CreateTime" HeaderText="创建时间" />
</Columns>
</asp:GridView>
</p>
</form>

后台cs文件

代码 代码如下:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load();
}
}
private void load()//就实现绑定
{
Jquery三层实现删除功能.Model.T_News mm = new Model.T_News();
Jquery三层实现删除功能.BLL.T_News bb = new BLL.T_News();
string sqlwhere = "Id<25";
ds = bb.GetList(sqlwhere);//获取dataset绑定
this.GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
//遍历每一行
foreach (GridViewRow item in GridView1.Rows)//一定要记住这里是gridviewrow不是datarow
{
CheckBox cb = (CheckBox)item.FindControl("CheckBox3");//找到这个选中项
if (cb.Checked)//选中
{
Jquery三层实现删除功能.BLL.T_News bb = new BLL.T_News();
if (bb.DeleteList(item.Cells[1].Text))//调用bb.DeleteList(id)删除
{
Response.Write("删除成功");
}
load();

觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!

本文固定链接: http://www.js-code.com/js/js_1399.html