日期:2014-05-17 浏览次数:20572 次
<%@ Page Language="C#" EnableViewState="true" %> <%@ Import Namespace="System.Xml" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public System.Data.DataTable CreateDataTable() { System.Data.DataTable dataTable1 = new System.Data.DataTable("BlogUser"); System.Data.DataRow dr; dataTable1.Columns.Add(new System.Data.DataColumn("Id", typeof(System.Int32))); dataTable1.Columns.Add(new System.Data.DataColumn("Title", typeof(System.String))); for (int i = 0; i < 8; i++) { dr = dataTable1.NewRow(); dr[0] = i; dr[1] = "【孟子E章】" + i.ToString(); dataTable1.Rows.Add(dr); } return dataTable1; } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { DataList1.DataSource = CreateDataTable(); DataList1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { CheckBox isDeleted; foreach (DataListItem anItem in DataList1.Items)//遍历所有checkbox找出用户选择的项 { isDeleted = ((CheckBox)anItem.FindControl("Delete")); if (isDeleted.Checked) { string bianh = DataList1.DataKeys[anItem.ItemIndex].ToString(); Response.Write("<li>" + bianh); } } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>无标题页</title> </head> <body onclick="myfunction()"> <form id="form1" runat="server"> <asp:DataList ID="DataList1" runat="server" DataKeyField="Id"> <ItemTemplate> <div> <asp:CheckBox ID="Delete" runat="server" /> <%#Eval("Title") %></div> </ItemTemplate> </asp:DataList> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="height: 21px" Text="Button" /> </form> </body> </html>