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>
&nbsp;&nbsp;&nbsp;&nbsp;-----------------
<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 删除确认框 传多个参数的更多相关文章

  1. LinkButton中添加删除确认框

    LinkButton1.Attributes.Add("onclick", "javascript:return confirml('确认删除?');");

  2. JavaScript删除确认框

    1〉 <a href="javascript:if(confirm('确实要删除吗?'))location='jb51.php?id='">删除</a>

  3. 判断小数点位数不超过2位的JS代码和在删除确认框里面插JS代码

    <script type="text/javascript"> function checkDecimals(){ var decallowed = 2; var re ...

  4. js确认框confirm()用法实例详解

    先为大家介绍javascript确认框的三种使用方法,具体内容如下 第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认. ? 1 2 3 4 5 6 7 8 ...

  5. javaScript 删除确认实现方法总结分享

    第一种方法:挺好用的,确认以后才能打开下载地址页面.原理也比较清晰.主要用于删除单条信息确认.<SCRIPT LANGUAGE=javascript> function p_del() { ...

  6. js实现删除确认提示框

    js实现删除确认提示框 一.实例描述 防止用户小心单击了“删除”按钮,在用户单击“删除”按钮后,给出一个提示,让用户确认此次操作是否正确. 二.效果 三.代码 <!DOCTYPE html> ...

  7. Vue 下拉框值变动事件传多个参数

    在使用 Vue 进行开发时,下拉框值变动事件 @change 是很常用的. 其传参一般分为两种方式:默认传参和自定义传参. 默认传参 @change 默认会传选中项标识的参数,在传参处不用定义,在方法 ...

  8. Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码

    关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...

  9. ABP的确认框

    使用之前,是需要添加对abp.sweet-alert.js的引用,否则就无法正常使用. 确认框 abp.message.info('some info message', 'some optional ...

随机推荐

  1. tomcat之一:指定tomcat运行时JDK版本

    tomcat作为日常开发的web应用服务器,给开发测试带来了很多便利,tomcat的运行依赖JDK的支持,在安装JDK时经常会配置环境变量:JAVA_HOME.CLASSPAT,且需要添加path变量 ...

  2. 使用Spring Boot来加速Java web项目的开发

    我想,现在企业级的Java web项目应该或多或少都会使用到Spring框架的. 回首我们以前使用Spring框架的时候,我们需要首先在(如果你使用Maven的话)pom文件中增加对相关的的依赖(使用 ...

  3. WebApi系列~FromUri参数自动解析成实体的要求

    回到目录 关于webapi我之前写了一些文章,大家可以根据目录去浏览,今天要说的是个怪问题,也是被我忽略的一个问题,当你的Url参数需要被Api自动解析成实体的属性,实事上是要有条件的,不是所以属性都 ...

  4. Nodejs与ES6系列3:generator对象

    3.generator对象 Generator函数是ES6提供的一种异步编程解决方案,语法行为与传统函数完全不同.Generator的中文翻译是生成器,它是ECMAScript6(代号harmory) ...

  5. JavaScript基本语法(二)

    上篇博文写到JavaScript的数据类型.JavaScript包括了字符串(String).数字(Number).布尔(Boolean).数组(Array).对象(Object).空(Null).未 ...

  6. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(一)GIS一张图的系统开发环境以及flexviewer框架

    系统的GIS功能实现是基于arcgis api for flex,首先附上系统的主界面图,接下来的是对主界面的模块功能详细讲解: 一.GIS环境软件安装 (1)arcgis desktop的安装,要是 ...

  7. Android 更新UI的几种方式

    1.Activity的 runOnUiThread textView = (TextView) findViewById( R.id.tv ); new Thread(new Runnable() { ...

  8. 在TableView上添加悬浮按钮

    如果直接在TableVIewController上贴Button的话会导致这个会随之滚动,下面解决在TableView上实现位置固定悬浮按钮的两种方法: 1.在view上贴tableView,然后将悬 ...

  9. Android项目实战(二十六):蓝牙连接硬件设备开发规范流程

    前言: 最近接触蓝牙开发,主要是通过蓝牙连接获取传感器硬件设备的数据,并进行处理. 网上学习一番,现整理出一套比较标准的 操作流程代码. 如果大家看得懂,将来只需要改下 硬件设备的MAC码 和 改下对 ...

  10. java HelloWorld 提示“错误: 找不到或无法加载主类 HelloWorld“解决方案

    在检查环境变量等前提工作准确无误后,注意要配好CLASSPATH,仍然报“错误: 找不到或无法加载主类 HelloWorld“. 本人工程目录:mygs-maven/src/main/java/hel ...