list.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="firstsort_list.aspx.cs" Inherits="background_firstsort_list" %> <!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>无标题页</title> <link href="../../CSS/style.css" mce_href="CSS/style.css" type="text/css" rel="stylesheet"/> </head> <body> <form id="form1" runat="server"> <div> <span style="font-size: 16pt; color: #ff0033; font-family: Verdana" mce_style="font-size: 16pt; color: #ff0033; font-family: Verdana"><strong> 一级分类列表页面<br /> </strong></span> <asp:DataGrid AllowPaging="True" PageSize="5" PagerStyle-HorizontanAlign="Right" PagerStyle-Mode="NumericPages" OnPageindexChanged="OnChangePage" Headerstyle-BackColor="#AAAADD" AlternatingItemStyle-BackColor="#FFFFCD" BorderColor="Black" CellPadding="3" CellSpacing="0" AutoGenerateColumns="false" id="FirstSortGird" runat="server" Width="350px"> <Columns> <asp:TemplateColumn HeaderText="选择"> <ItemStyle Width="50px"></ItemStyle> <ItemTemplate> <asp:CheckBox ID="DeleteCheckBox" runat="server" Text=""> </asp:CheckBox> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn DataField="sort_id" HeaderText="一级分类ID"> <ItemStyle Width="80px" ></ItemStyle> </asp:BoundColumn> <asp:BoundColumn DataField="sort_name" HeaderText="一级分类名称"> <ItemStyle Width="140px" HorizontalAlign="Left"></ItemStyle> </asp:BoundColumn> <asp:HyperLinkColumn Text="修改" HeaderText="修改" DataNavigateUrlField="sort_id" DataNavigateUrlFormatString="add_firstsort.aspx?sort_id={0}" Target="mainFrame" /> </Columns> <PagerStyle Mode="NumericPages" /> <AlternatingItemStyle BackColor="#FFFFCD" /> <HeaderStyle BackColor="#AAAADD" /> </asp:DataGrid> <br /> <asp:CheckBox ID="SelectAllCheckBox" runat="server" AutoPostBack="true" Text="全选" OnCheckedChanged="SelectAllCheckBox_CheckedChanged" /> <asp:Button ID="DeleteButton" runat="server" OnClick="DeleteButton_Click" Text="删除" /> <br /> <span style="color: #ff0033" mce_style="color: #ff0033">注意:删除一级分类时,将会把与之关联的二级分类信息和资源列表信息全部删除。 </span></div> </form> </body> </html> list.aspx.cs /** * @brief 当删除按钮点击的时候,执行该函数 * @param sender Object类对象 * @return e 事件数据类对象 * @remark None */ protected void DeleteButton_Click(object sender, EventArgs e) { CheckBox checkBox = null; String strSortID = ""; // 分类ID组合 bool bAllNotChecked = true; // 是否都没选中 foreach (DataGridItem item in FirstSortGird.Items) { // 找到CheckBox控件,这里不能用FirstSortGrid调用FindControl checkBox = (CheckBox)item.FindControl("DeleteCheckBox"); if (checkBox != null && checkBox.Checked) { if (strSortID == "") { strSortID = strSortID + item.Cells[1].Text; } // 如果不是第一个数字,要加","符号隔开 else { strSortID = strSortID + "," + item.Cells[1].Text; } bAllNotChecked = false; } } if (bAllNotChecked) { Alert.MessageBox("请选择要删除的一级分类!"); return; } String strSql = "DELETE FROM first_sort WHERE sort_id IN(" + strSortID + ")"; if (FirstSortBean.DeleteFirstSort(strSql)) { Alert.MessageBox("删除一级分类成功!"); Response.Write("<mce:script type="text/javascript"><!-- window.location.href='../right.html' // --></mce:script>"); } else { Alert.MessageBox("删除一级分类失败!"); } } /** * @brief 当全选复选框点击的时候,执行该函数 * @param sender Object类对象 * @return e 事件数据类对象 * @remark None */ protected void SelectAllCheckBox_CheckedChanged(object sender, EventArgs e) { CheckBox checkBox; foreach (DataGridItem item in FirstSortGird.Items) { checkBox = (CheckBox)item.FindControl("DeleteCheckBox"); if (checkBox != null) { checkBox.Checked = !checkBox.Checked; } } }