.aspx

<div>
<asp:DataList ID="DataList1" runat="server" Width="355px"
onitemcommand="DataList1_ItemCommand" DataKeyField="id">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" />
<asp:Label ID="Label3" Width="70px" runat="server" Text="ID"></asp:Label>
<asp:Label ID="Label4" Width="170px" runat="server" Text="imageUrl"></asp:Label>
<asp:Label ID="Label5" runat="server" Text="handle"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:Label ID="Label1" Width="70px" runat="server" Text='<%# Eval( "id") %>'></asp:Label>
<asp:Label ID="Label2" Width="170px" runat="server" Text='<%# Eval("imageUrl") %>'></asp:Label>
<asp:Button ID="Button1" runat="server" CommandName="singleDelete" Text="delete" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Button2" runat="server" CommandName="mutlDelete" Text="delete" />
</FooterTemplate>
</asp:DataList>
</div>

.aspx.cs

 public partial class _234DeleteData : System.Web.UI.Page
{
ShowImageBll showImageBll = new BLL.ShowImageBll(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
}
} private void BindDataList()
{
DataSet ds = showImageBll.GetList();
DataList1.DataSource = ds;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
switch (e.CommandName)
{
case "singleDelete":
int id = int.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());
if (showImageBll.GetList()!=null)
{
showImageBll.DeleteSingleList(id);
Response.Write("<script>alert('删除成功!')</script>");
BindDataList();//重新绑定数据库
}
else
{
showImageBll.DeleteSingleList(id);
Response.Write("<script>alert('删除失败!')</script>");
}
break;
case "mutlDelete": DataListItemCollection dlic = DataList1.Items;//创建一个DataList列表项集合对象
for (int i = ; i < dlic.Count; i++)
{
if (dlic[i].ItemType == ListItemType.AlternatingItem || dlic[i].ItemType == ListItemType.Item)
{
CheckBox cb=(CheckBox)dlic[i].FindControl("CheckBox1");
if (cb.Checked)
{
int id1 = int.Parse(DataList1.DataKeys[dlic[i].ItemIndex].ToString());
showImageBll.DeleteSingleList(id1);
}
}
}
BindDataList();//重新绑定数据库
break; } }
}

总结:

【1】数据源读取Text='<%# DataBinder.Eval(Container.DataItem, "id") %>' 可简化为  Text='<%# Eval( "id") %>'

【2】int id = int.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());//读取当前列的key值
【3】 DataListItemCollection dlic = DataList1.Items;//创建一个DataList列表项集合对象

《ASP.NET1200例》ASP.Net 之Datalist数据删除(支持批量)的更多相关文章

  1. 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定

    aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...

  2. 《ASP.NET1200例》在DataList里编辑和删除数据

    学习内容:如何创建一个支持编辑和删除数据的DataList.增加编辑和删除功能需要在DataList的ItemTemplate和EditItemTemplate里增加合适的控件,创建对应的事件处理,读 ...

  3. 《ASP.NET1200例》<asp:DataList>分页显示图片

    aspx页面代码 <asp:DataList ID="dlPhoto" runat="server" Height="137px" W ...

  4. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<二>

    ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示 为什么使用ListView+DataPager的方式实现分页显示? .net提供的诸多数据绑定控件,每一种都有它自己 ...

  5. 《ASP.NET1200例》ListView 控件与DataPager控件的结合<一>

    分页     在前一部分开始时介绍的原 HTML 设计中内含分页和排序,所以根据规范完整实现该网格的任务尚未完成.我们先分页,然后再排序. ListView 控件中的分页通过引入另一个新控件 Data ...

  6. 《ASP.NET1200例》<ItemTemplate>标签在html里面有什么具体的作用

    严格的来说 <ItemTemplate> 在html中无意义,他只是针对诸如 Repeater.DataList.GridView中的一个模板 至于里面的含义,你可以这样想,既然Repea ...

  7. 《ASP.NET1200例》C#在网页上编写动态时钟

    包含Timer类的命名空间有3个 Timer Class (System.Threading)‎ Timer Class (System.Windows.Forms)‎ 一般用于窗体程序 Timer  ...

  8. 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片

    aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...

  9. 《ASP.NET1200例》ListView控件之修改,删除与添加

    aspx <body> <form id="form1" runat="server"> <div> <asp:Lis ...

随机推荐

  1. nginx 配置虚拟主机

    文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...

  2. OC基础--构造方法

    OC语言中类的构造方法学了两种: 一.方法一:[类名 new] 例:[Person new] 缺点:可扩展性不强,假如在Person类中有_age 成员变量,在初始化时想让_age 中的值为20,ne ...

  3. Cas_Java客户端登录相关过滤器的处理流程

    首先了解一下CAS登录原理: 1.CAS结构中一般包含CAS服务器(Cas验证服务器).应用服务器(程序所在服务器).客户端(web浏览器)三个部分. 2.客户端向应用服务器发出请求,由于未登录,会被 ...

  4. 洛谷P1130 红牌

    题目描述 某地临时居民想获得长期居住权就必须申请拿到红牌.获得红牌的过程是相当复杂 ,一共包括N个步骤.每一步骤都由政府的某个工作人员负责检查你所提交的材料是否符合条件.为了加快进程,每一步政府都派了 ...

  5. HDU2888 Check Corners

    Description Paul draw a big m*n matrix A last month, whose entries Ai,j are all integer numbers ( 1 ...

  6. Unable to open liblaunch_sim.dylib. Try reinstalling Xcode or the simulator

    关于Xcode7 Beta报错 simulator runtime is not available. Unable to open liblaunch_sim.dylib Try reinstall ...

  7. DFS & BFS

    DFS 深度优先 BFS 广度优先 DFS或者BFS都是在联通区域内遍历节点的方法 用在二叉树上DFS有preOreder,inOrder,postOrder,BFS就是层次遍历. 在二叉树上的节点, ...

  8. xss实例-输出在<script></script>之间的情况

    1. 我们找到这么一个点,也是输入和输出都未过滤的一个点.相比教程第一例,其特殊之处在于,是输出在了 <script>[输出]</script>之间. http://activ ...

  9. B/S C/S架构的界面测试

    网站是B/S架构的典型,从做网站的有限经验来整理一下B/S测试的基本要点,并把它与C/S进行区分. 与C/S相比,以下4个测试是除了常用测试外还要注意的: (1)链接测试 (2)表单测试 (3)脚本测 ...

  10. mysql 的设置

    网上的一些文章都已经比较老了,现在版本高了之后,其实配置是很省力的(不考虑什么负载的话) 分享全过程,出了文中提到的安装epel rpmfushion 源指令不同外,其他的过程也适用与Centos 5 ...