aspx

<script type="text/javascript">
function CheckAll(Obj) {
var AllObj = document.all;
if (Obj.checked)//全选
{
for (var i = ; i < AllObj.length; i++) {
if (AllObj[i].type == "checkbox") {
AllObj[i].checked = true;
}
}
}
else//反选
{
for (var i = ; i < AllObj.length; i++) {
if (AllObj[i].type == "checkbox") {
AllObj[i].checked = false;
}
}
}
} </script>
<body>
<form id="form2" runat="server">
<div>
<asp:DataList ID="DataList1" runat="server" Width="465px"
onitemcommand="DataList1_ItemCommand" DataKeyField="id">
<HeaderTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" onclick="return CheckAll(this)" />
<asp:Label ID="Label3" Width="50px" runat="server" Text="ID"></asp:Label>
<asp:Label ID="Label4" Width="50px" runat="server" Text="姓名"></asp:Label>
<asp:Label ID="Label5" Width="50px" runat="server" Text="性别"></asp:Label>
<asp:Label ID="Label7" Width="100px" runat="server" Text="电话"></asp:Label>
<asp:Label ID="Label6" Width="50px" runat="server" Text="操作:"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:Label ID="Label1" Width="50px" runat="server" Text='<%# Eval( "id") %>'></asp:Label>
<asp:Label ID="Label2" Width="50px" runat="server" Text='<%# Eval( "StuName") %>'></asp:Label>
<asp:DropDownList ID="ddlSex" Width="50px" runat="server">
<asp:ListItem Value="" > 男 </asp:ListItem>
<asp:ListItem Value=""> 女 </asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label8" Width="100px" runat="server" Text='<%# Eval( "StuPhone") %>'></asp:Label>
<asp:Button ID="Button1" Width="50px" runat="server" CommandName="singleDelete" Text="delete" />
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Button2" runat="server" CommandName="mutlDelete" Text="deleteAll" />
</FooterTemplate>
</asp:DataList>
</div>
</form>
</body>

aspc.cs

public partial class _238DllInGridView : System.Web.UI.Page

    {
ShowImageBll showBll = new ShowImageBll();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataList();
sexBind();
}
} public void BindDataList() {
DataSet ds = showBll.GetStudentList();
DataList1.DataSource = ds;
DataList1.DataBind();
} public void sexBind()
{
DataSet ds = showBll.GetStudentList();
DropDownList ddlSex;
for (int i = ; i < DataList1.Items.Count;i++ )
{
if (ds.Tables[].Rows[i]["StuSex"].ToString() == "男")//数据库性别没有设置,ddlSex控件将默认设置为“男”
{
ddlSex = (DropDownList)DataList1.Items[i].FindControl("ddlSex");
ddlSex.SelectedValue = "";
}
if (ds.Tables[].Rows[i]["StuSex"].ToString() == "女")
{
ddlSex = (DropDownList)DataList1.Items[i].FindControl("ddlSex");
ddlSex.SelectedValue="";
}
} }
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
switch (e.CommandName) {
case "singleDelete":
int id = int.Parse(DataList1.DataKeys[e.Item.ItemIndex].ToString());
showBll.DeleteStudent(id);
Response.Write("<script>alert('删除成功!')</script>");
BindDataList();
break;
case "mutlDelete": DataListItemCollection dlic = DataList1.Items;//创建一个DataList列表项集合对象
for (int i = ; i < dlic.Count; i++)
{
CheckBox cb=(CheckBox)dlic[i].FindControl("CheckBox1");
if (cb.Checked)
{
int id1 = int.Parse(DataList1.DataKeys[dlic[i].ItemIndex].ToString());
showBll.DeleteStudent(id1);
} }
BindDataList();//重新绑定数据库
break; }
}
}

《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. web页面动态加载UserControl,并调用用户控件中的方法来初始化控件

    1,HTML页 头部注册: <%@ Register Src="~/WorkLog/WorkLogNewV1/UserControl/CeShiBu.ascx" TagPre ...

  7. 《ASP.NET1200例》解决母版页报错“内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。”

    VS2005下,添加了母版页这个控件,我们可以讲N个页面中共同的部分放在母版页来实现,并让WEB窗体集成自我们的母版页,就可以让我们的站点具有统一的风格了.在VS2005SP1之前的版本中,我们只能创 ...

  8. 《ASP.NET1200例》实现投票的用户控件

    用户控件ascx <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="24 ...

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

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

随机推荐

  1. Qt模型/视图框架----简单的例子

    #include<qapplication.h> #include<qfilesystemmodel.h> #include<qtreeview.h> #inclu ...

  2. 嘻哈帮天通苑_poppin——张锋

    l click_me

  3. Java虚拟机的功能

    1:通过ClassLoader寻找和装载class文件 2:解释字节码成为指令并执行,提供class文件的运行环境.即将字节码转换为不同OS下可执行的机器码指令. 3:进行垃圾回收. 4:提供与硬件交 ...

  4. 【CodeForces 604B】F - 一般水的题1-More Cowbe

    Description Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter ...

  5. 【ZOJ 3870】 Team Formation

    题意 n个数,找出有几对a.b 符合 a ^ b > max(a,b) .^表示异或号 分析 对于数a,如果它的二进制是: 1 0 1  0 0 1,那么和它 ^ 后 能比他大的数就是: 0 1 ...

  6. BZOJ-2875 随机数生成器 矩阵乘法快速幂+快速乘

    题目没给全,吃X了... 2875: [Noi2012]随机数生成器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 1479 Solved: 829 ...

  7. Openjudge 8782 乘积最大

    伤心,感冒了根本没精力肝题,只能做点小的 描述 今年是国际数学联盟确定的“2000——世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的数学智力 ...

  8. mac下使用minicom

    各种艰辛就不一一表过了,反正最后无奈的有捡起了minicom. 因为使用的brew,所以安装相对比较容易: brew install minicom 和Linux下一样的操作,先是查看硬件设备名称: ...

  9. DLUTOJ 1033 Matrix

    传送门 Time Limit: 2 Sec  Memory Limit: 128 MB Description We often use the matrix to analyze reality m ...

  10. TOJ3540Consumer(有依赖的背包)

    http://acm.tju.edu.cn/toj/showp3540.html3540.   Consumer Time Limit: 2.0 Seconds   Memory Limit: 655 ...