一个很好的反选的例子

Html文件内容:
<script language="javascript">
            
function fun_option(obj)
            
{
                document.Form1.hiduserid.value
=obj.value;
            }
            
            
function chkAll_true()
            
{
                
var chkall= document.all["chkAll"];
                
var chkother= document.getElementsByTagName("input");
                
for (var i=0;i<chkother.length;i++)
                
{
                    
if( chkother[i].type=='checkbox')
                    
{
                        
if(chkother[i].id.indexOf('chkExport')>-1)
                        
{
                            
if(chkall.checked==true)
                            
{
                                chkother[i].checked
=true;
                            }

                            
else
                            
{
                                chkother[i].checked
=false;
                            }

                        }

                    }

                }

            }

            
            
function Delete()
            
{
                
var  al = new Array();
                
var chkother= document.getElementsByTagName("input");
                
for(var i=0,j=0;i<chkother.length;i++)
                
{
                    
if( chkother[i].type =='checkbox')
                    
{
                        
if(chkother[i].id.indexOf('chkExport')>-1)
                        
{
                            
if(chkother[i].checked==true)
                            
{
                                al[j] 
=chkother[i].value;
                                j
++;
                            }

                        }

                    }

                }

                
if (al == "")
                
{
                    alert('You need to select a row 
in the list before selecting Delete.\r\nPlease select a row and try again.');
                }

                
else if (window.confirm("Are you sure to delete all these?"))
                
{
                    
var deleteID='<%=btndelete.ClientID%>';
                    window.document.all(deleteID).click();
                }

                event.cancelPostBack
=true;                
            }

        
</script>

下面显示的全先和删除文件
全选/取消
<INPUT id="chkAll" onclick="chkAll_true()" type="checkbox">全选/取消<asp:button id="btndelete" runat="server" Text="删除"></asp:button>
DataGrid中的反选列
                                <asp:TemplateColumn>
                                    
<HeaderStyle Width="10px"></HeaderStyle>
                                    
<ItemTemplate>
                                        
<asp:CheckBox id="chkExport" Runat="server"></asp:CheckBox>
                                    
</ItemTemplate>
                                
</asp:TemplateColumn>
后台CS 文件中的内容:
btndelete_Click

        
delete
posted @ 2006-08-26 01:26  wenanry  阅读(268)  评论(0编辑  收藏  举报