repeater 删除确认框 传多个参数
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page
{
private const string connectionStr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\QianTao\App_Data\db.mdf;Integrated Security=True;User Instance=True"; protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
SetBind();
}
} protected void rptClass_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//判断是否添加类别
if (e.CommandName == "AddClass")
{
TextBox tb = e.Item.FindControl("txtClassName") as TextBox;
using(SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using(SqlCommand cmd = new SqlCommand("insert into tb_Class(className) values(@className)", conn))
{
cmd.Parameters.AddWithValue("@className", tb.Text);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
//判断是否删除类别
if (e.CommandName == "DelClass")
{
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from tb_Module where classId=@classId;delete from tb_Class where id=@classId", conn))
{
cmd.Parameters.AddWithValue("@classId", e.CommandArgument);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
//判断是否修改类别
if (e.CommandName == "UpdateClass")
{
TextBox tb = e.Item.FindControl("txtClassName") as TextBox;
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("update tb_Class set className=@className where id=@id", conn))
{
cmd.Parameters.AddWithValue("@className", tb.Text);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
//判断是否添加模块
if (e.CommandName == "AddModule")
{
TextBox tb = e.Item.FindControl("txtModuleName") as TextBox;
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("insert into tb_Module(classId,moduleName)values(@classId,@moduleName)", conn))
{
cmd.Parameters.AddWithValue("@moduleName", tb.Text);
cmd.Parameters.AddWithValue("@classId", e.CommandArgument);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
} /// <summary>
/// 嵌套repeater的ItemCommand事件
/// </summary>
protected void rptModule_ItemCommand(object source, RepeaterCommandEventArgs e)
{
//判断是否删除模块
if (e.CommandName == "DelModule")
{
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("delete from tb_Module where id=@Id;", conn))
{
cmd.Parameters.AddWithValue("@Id", e.CommandArgument);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
//判断是否修改模块
if (e.CommandName == "UpdateModule")
{
TextBox tb = e.Item.FindControl("txtModuleName") as TextBox;
using (SqlConnection conn = new SqlConnection(connectionStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("update tb_Module set moduleName=@Name where id=@id", conn))
{
cmd.Parameters.AddWithValue("@Name", tb.Text);
cmd.Parameters.AddWithValue("@id", e.CommandArgument);
cmd.ExecuteNonQuery();
SetBind();
}
}
}
} /// <summary>
/// 绑定Repeater
/// </summary>
private void SetBind()
{
DataSet ds = new DataSet();
using(SqlConnection conn = new SqlConnection(connectionStr))
{
SqlDataAdapter adapter =
new SqlDataAdapter("select * from tb_Class",conn);
adapter.Fill(ds);
}
rptClass.DataSource = ds;
rptClass.DataBind();
} protected void rptClass_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rpt = e.Item.FindControl("rptModule") as Repeater;
//找到分类Repeater关联的数据项
DataRowView rowv = (DataRowView)e.Item.DataItem;
//提取分类ID
int id = (int)rowv["id"];
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection(connectionStr))
{
SqlDataAdapter adapter =
new SqlDataAdapter("select * from tb_Module where classId="+ id +"", conn);
adapter.Fill(ds);
} rpt.DataSource = ds;
rpt.DataBind();
} }
}
ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>嵌套RepeaterDEMO</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptClass" runat="server" OnItemCommand="rptClass_ItemCommand" OnItemDataBound="rptClass_ItemDataBound">
<HeaderTemplate>
<table>
<tr style=" border-color: rgb(51, 58, 51) !important; background-image: none !important;">">
<td>
添加类别:
<asp:TextBox ID="txtClassName" runat="server">
</asp:TextBox>
<asp:Button ID="btnAddClass" runat="server" CommandName="AddClass" Text="添加" />
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style=" border-color: rgb(51, 58, 51) !important; background-image: none !important;">">
<td>
<asp:Button ID="btnDelClass" CommandArgument='<%# Eval("id") %>' CommandName="DelClass" runat="server" Text="删除类别" />
<asp:TextBox ID="txtClassName" runat="server" Text='<%# Eval("className") %>'>
</asp:TextBox>
<asp:Button ID="btnUpdateClass" CommandArgument='<%# Eval("id") %>' CommandName="UpdateClass" runat="server" Text="修改类别" />
</td>
</tr>
<tr>
<td>
添加模块:
<asp:TextBox ID="txtModuleName" runat="server">
</asp:TextBox>
<asp:Button ID="btnAddModule" runat="server" CommandName="AddModule" CommandArgument='<%# Eval("id") %>' Text="添加" />
</td>
</tr>
<tr>
<td>
<asp:Repeater ID="rptModule" runat="server"
OnItemCommand='rptModule_ItemCommand'>
<ItemTemplate>
<tr>
<td>
-----------------
<asp:Button ID="btnDeleteModule" CommandArgument='<%# Eval("id") %>' CommandName="DelModule" runat="server" Text="删除模块" />
<asp:TextBox ID="txtModuleName" Text='<%# Eval("moduleName") %>' runat="server"></asp:TextBox>
<asp:Button ID="btnUpdateModule" CommandArgument='<%# Eval("id") %>' CommandName="UpdateModule" runat="server" Text="修改模块" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("nid")+","+this.listpage.CurrentPageIndex.ToString()%>' CommandName="delete">删除</asp:LinkButton> if (e.CommandName == "delete")
{
string[] cmdArg = e.CommandArgument.ToString().Split(','); string strMsg = "确定要删除吗?";
string strUrl_Yes = "deleteUser.aspx?qid=" + cmdArg[] + "&page=UserList&pno=" + cmdArg[];
string strUrl_No = ""; // page + ".aspx?msg=用户取消!&pno=" + Request.QueryString["pno"].ToString(); Response.Write("<Script Language='JavaScript'>if ( window.confirm('" + strMsg + "')) {window.location.href='" + strUrl_Yes + "'} else {};</script>"); return;
}
repeater 删除确认框 传多个参数的更多相关文章
- LinkButton中添加删除确认框
LinkButton1.Attributes.Add("onclick", "javascript:return confirml('确认删除?');");
- JavaScript删除确认框
1〉 <a href="javascript:if(confirm('确实要删除吗?'))location='jb51.php?id='">删除</a>
- 判断小数点位数不超过2位的JS代码和在删除确认框里面插JS代码
<script type="text/javascript"> function checkDecimals(){ var decallowed = 2; var re ...
- js确认框confirm()用法实例详解
先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...
- javaScript 删除确认实现方法总结分享
第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认.<SCRIPT LANGUAGE=javascript> function p_del() { ...
- js实现删除确认提示框
js实现删除确认提示框 一.实例描述 防止用户小心单击了“删除”按钮,在用户单击“删除”按钮后,给出一个提示,让用户确认此次操作是否正确. 二.效果 三.代码 <!DOCTYPE html> ...
- Vue 下拉框值变动事件传多个参数
在使用 Vue 进行开发时,下拉框值变动事件 @change 是很常用的. 其传参一般分为两种方式:默认传参和自定义传参. 默认传参 @change 默认会传选中项标识的参数,在传参处不用定义,在方法 ...
- Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码
关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...
- ABP的确认框
使用之前,是需要添加对abp.sweet-alert.js的引用,否则就无法正常使用. 确认框 abp.message.info('some info message', 'some optional ...
随机推荐
- Java--设计模式心得体会
1.策略模式: 策略模式就是将能够通用的算法,封装成不同的组件,实现同一个接口,使之可以互换. 例子:SpringMVC的9大组件,都采用策略模式.比如HandlerMethodArgumentRes ...
- 从零开始学 Java - Spring 一主多从、多主多从 数据库配置
待会苹果要开发布会 我写完这篇文章就准备去看发布会了,因为我买了好几包瓜子和啤酒.由于苹果的保密做的越来越差劲,该曝光的信息差不多全部曝光了,我们这种熬夜看发布会的只不过是让这些信息更加真实,或者说是 ...
- Android 实现QQ扩展listview(expandlistview)
Android 实现QQ扩展listview(expandlistview) <?xml version="1.0" encoding="utf-8"?& ...
- 【工业串口和网络软件通讯平台(SuperIO)教程】九.重写通讯接口函数,实现特殊通讯方式
SuperIO相关资料下载:http://pan.baidu.com/s/1pJ7lZWf 1.1 统一的IO接口 开发一套设备驱动同时具备串口和网络通讯能力,通讯接口在逻辑上是统一的,在此基础 ...
- 《对象及DOM知识点及其应用1》
1.图片间的来回切换用if{}else{}; <超链接方式的切换图片(常用)>如:<a href="../images1/1-small.jpg" id=&quo ...
- javascript 实现des解密加密
//Paul Tero, July 2001 //http://www.tero.co.uk/des/ // //Optimised for performance with large blocks ...
- Intent(三)向下一个活动传递数据
向下传递活动很简单,可以我采用putExtra()方法的重载,把我们想要传递的数据暂时放在intent中,启动活动时从这里取就可以了. 首先我们在MainActivity(主活动)显式声明intent ...
- Watir-WebDriver关于交互式等待方法,告别一味sleep时代
有交互就有等待,等待页面加载完毕的时间怎么处理呢? 有人说sleep: sleep N #等待N秒后继续执行 怎么才能告别毫无意义的命令呢? 接下来介绍一下Watir-Webdriver为我们提供等待 ...
- Sql--order by、desc降序、top
---------通过order by 语句进行排序: --1.降序order by 列名desc --2.升序order by 列名 或order by 列名asc --3.order by语句 ...
- RHEL 5.7 Yum配置本地源[Errno 2] No such file or directory
在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源时,遇到了"Errno 5] OSError: [Errno 2] No such ...