DataGrid 完全攻略之三(实现删除全选或者全不选)-阿里云开发者社区

开发者社区> 开发与运维> 正文

DataGrid 完全攻略之三(实现删除全选或者全不选)

简介:

前台代码:html
ExpandedBlockStart.gif<%@ Page language="c#" Codebehind="SelAndDropAll.aspx.cs" AutoEventWireup="false" Inherits="MsDataGrid.SelAndDropAll" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>DataGrid使用举例</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<FONT face="宋体">
None.gif                
<asp:DataGrid id="dgShow" style="Z-INDEX: 101; LEFT: 31px; POSITION: absolute; TOP: 93px" runat="server" Width="842px" Height="172px" BorderColor="Tan" BorderWidth="1px" BackColor="LightGoldenrodYellow" CellPadding="2" GridLines="None" ForeColor="Black" PageSize="1" AutoGenerateColumns="False">
None.gif                    
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
None.gif                    
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
None.gif                    
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
None.gif                    
<FooterStyle BackColor="Tan"></FooterStyle>
None.gif                    
<Columns>
None.gif                        
<asp:BoundColumn DataField="StudentID" ReadOnly="True" HeaderText="学生ID"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentName" HeaderText="学生姓名"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentPass" HeaderText="密码"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Sex" HeaderText="性别"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Birthday" HeaderText="生日" DataFormatString="{0:yyyy-M-d}"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Email" HeaderText="邮件地址"></asp:BoundColumn>
None.gif                        
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="操作" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
None.gif                        
<asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
None.gif                        
<asp:TemplateColumn HeaderText="选择">
None.gif                            
<HeaderTemplate>
None.gif                                
<asp:CheckBox id="cbAll" runat="server" OnCheckedChanged="CheckAll" Text="全选" AutoPostBack="True"></asp:CheckBox>
None.gif                            
</HeaderTemplate>
None.gif                            
<ItemTemplate>
None.gif                                
<asp:CheckBox id="cbSelect" runat="server" AutoPostBack="True"></asp:CheckBox>
None.gif                            
</ItemTemplate>
None.gif                        
</asp:TemplateColumn>
None.gif                    
</Columns>
None.gif                    
<PagerStyle HorizontalAlign="Center" ForeColor="DarkSlateBlue" BackColor="PaleGoldenrod"></PagerStyle>
None.gif                
</asp:DataGrid>
None.gif                
<asp:Button id="btnDelete" style="Z-INDEX: 102; LEFT: 34px; POSITION: absolute; TOP: 47px" runat="server" Text="删除"></asp:Button></FONT>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>
None.gif

后台代码:cs
None.gif<%@ Page language="c#" Codebehind="SelAndDropAll.aspx.cs" AutoEventWireup="false" Inherits="MsDataGrid.SelAndDropAll" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>DataGrid使用举例</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<FONT face="宋体">
None.gif                
<asp:DataGrid id="dgShow" style="Z-INDEX: 101; LEFT: 31px; POSITION: absolute; TOP: 93px" runat="server" Width="842px" Height="172px" BorderColor="Tan" BorderWidth="1px" BackColor="LightGoldenrodYellow" CellPadding="2" GridLines="None" ForeColor="Black" PageSize="1" AutoGenerateColumns="False">
None.gif                    
<SelectedItemStyle ForeColor="GhostWhite" BackColor="DarkSlateBlue"></SelectedItemStyle>
None.gif                    
<AlternatingItemStyle BackColor="PaleGoldenrod"></AlternatingItemStyle>
None.gif                    
<HeaderStyle Font-Bold="True" BackColor="Tan"></HeaderStyle>
None.gif                    
<FooterStyle BackColor="Tan"></FooterStyle>
None.gif                    
<Columns>
None.gif                        
<asp:BoundColumn DataField="StudentID" ReadOnly="True" HeaderText="学生ID"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentName" HeaderText="学生姓名"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="StudentPass" HeaderText="密码"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Sex" HeaderText="性别"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Birthday" HeaderText="生日" DataFormatString="{0:yyyy-M-d}"></asp:BoundColumn>
None.gif                        
<asp:BoundColumn DataField="Email" HeaderText="邮件地址"></asp:BoundColumn>
None.gif                        
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" HeaderText="操作" CancelText="取消" EditText="编辑"></asp:EditCommandColumn>
None.gif                        
<asp:ButtonColumn Text="删除" HeaderText="删除" CommandName="Delete"></asp:ButtonColumn>
None.gif                        
<asp:TemplateColumn HeaderText="选择">
None.gif                            
<HeaderTemplate>
None.gif                                
<asp:CheckBox id="cbAll" runat="server" OnCheckedChanged="CheckAll" Text="全选" AutoPostBack="True"></asp:CheckBox>
None.gif                            
</HeaderTemplate>
None.gif                            
<ItemTemplate>
None.gif                                
<asp:CheckBox id="cbSelect" runat="server" AutoPostBack="True"></asp:CheckBox>
None.gif                            
</ItemTemplate>
None.gif                        
</asp:TemplateColumn>
None.gif                    
</Columns>
None.gif                    
<PagerStyle HorizontalAlign="Center" ForeColor="DarkSlateBlue" BackColor="PaleGoldenrod"></PagerStyle>
None.gif                
</asp:DataGrid>
None.gif                
<asp:Button id="btnDelete" style="Z-INDEX: 102; LEFT: 34px; POSITION: absolute; TOP: 47px" runat="server" Text="删除"></asp:Button></FONT>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>



本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/12/253185.html,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章