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. tomcat发布项目时,localhost可以访问,用ip地址不能访问,同时其他电脑也不能访问。

    最近在开发项目中,遇到的一个问题是:在 tomcat中发布一个web项目,但是发布成功后,只能用http://localhost:8080/aml访问项目,不能用http://172.0.0.1:80 ...

  2. java.io.FileNotFoundException:文件名、目录名或卷标语法不正确

    出现次错误的原因主要是在windows系统下创建文件需要遵循其文件名的规则.导致创建文件失败,从而提示filenotfound异常,文件未找到 Windows 中文件夹命名规则是: ① 文件名或文件夹 ...

  3. Struts-1和2的比较

    Struts1和Struts2都是MVC设计模式的经典应用框架,下文从代码,性能,测试,功能等方面对Struts1和Struts2进行简单比较,来看看Struts的高级版本在哪些方面进行了优化. (1 ...

  4. Emmet

    一.简介 Emmet (前身为 Zen Coding) ,不是软件也不是代码,是编辑器(如sublime text)的插件,相应的后缀文件(.html/.css)输入指定的缩写语法,按下tab键就能生 ...

  5. 【Matplotlib】 移动spines

    相关文档: Spines Axis container Transformations tutorial Spines 是连接轴刻度标记的线,而且标明了数据区域的边界. 他们可以被放置在任意位置.直到 ...

  6. Oracle自定义函数实例

    1. 传入一个值, 如果该值为0,则返回空. CREATE OR REPLACE FUNCTION Fun_Test(p IN NUMBER) RETURN VARCHAR2 IS v_Result ...

  7. BZOJ-1433 假期的宿舍 最大流+基础建图

    网络流练习ing.. 1433: [ZJOI2009]假期的宿舍 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 1748 Solved: 765 [S ...

  8. Bringing up interface eth0: Error:Connection activation failed:Device not managed by NetworkManager

    Just follow the below steps and everything will be ok...   1. Remove Network Manager from startup Se ...

  9. 洛谷U5653 宋荣子的小饼干

    题目描述 楼下机房的LYL有n个妹子,分别编号为a1,a2……an,每个妹子都拥有一定数量的小饼干.有一天,saruka没有吃晚饭,饿的不要不要的,这时,他忽然想起了LYL的妹子们有小饼干可以吃.于是 ...

  10. POJ 1466 Girls and Boys

    Girls and Boys Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=1466 Descripti ...