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. restful是什么

    resful是什么 rest是一种开发的风格,他不是框架,也没有类库,是一种约定 有什么不同 非restful的开发方式 当没有接触restful的时候,URL通常是动词,比如127.0.0.1:80 ...

  2. 正则匹配test

    var t='VARCHAR(5)' var pattern=/VARCHAR\(\d+\)/g pattern.test(t)//true test()返回false true 但是有哪位小伙伴能告 ...

  3. JAVA简单工厂模式(从现实生活角度理解代码原理)

    简单工厂模式(Simple Factory),说他简单是因为我们可以将此模式比作一个简单的民间作坊,他们只有固定的生产线生产固定的产品.也可以称他为静态工厂设计模式,类似于之前提到过静态代理设计模式, ...

  4. Android中的AlertDialog使用示例二(普通选项对话框)

    在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...

  5. 了解HTML 元素分类

    HTML中包含大量的标签, 这些标签在我们使用中发现会有小小的差别, 有的标签用了之后不会有太大的布局变化, 只是语义化, 而有的标签却会重起一行, 相当于自己回车了一次, 这就是不同标签元素的分类不 ...

  6. 了解HTML CSS布局(层叠样式表)

    CSS全称为"层叠样式表(Cascading Style Sheets)", 它主要是用于定义HTML内容在浏览器内显示的样式, 比如文字, 颜色, 视觉上的静态效果, 布局等等. ...

  7. 动态计算UITableViewCell高度

    动态计算UITableViewCell高度 UILabel in UITableViewCell Auto Layout - UILabel的属性Lines设为了0表示显示多行.Auto Layout ...

  8. SDWebImage的使用

    - setItem:(CustomItem *)item { _item = item; // 占位图片 UIImage *placeholder = [UIImage imageNamed:@&qu ...

  9. iOS开发之功能模块--长方形UIImage截取中间最大正方形区域

    这里直接用CoreGraphics的一些处理图片的方法,本身不难,但是有些时候用的不多,就会遗忘掉使用方法的细节.下面就直接展示关键源码,以便下次重复需求,就可以立马找回. 该方法中在UIImage的 ...

  10. 转载文档:Storm实战常见问题及解决方案

    该文档为实实在在的原创文档,转载请注明: http://blog.sina.com.cn/s/blog_8c243ea30101k0k1.html 类型 详细 备注 该文档是群里几个朋友在storm实 ...