javascript代码如下:

function SelectAll(spanChk)
        {
            
// Added as ASPX uses SPAN for checkbox 
            var oItem = spanChk.children;
            
var theBox=oItem.item(0)
            xState=theBox.checked;    

            elm=theBox.form.elements;
            
for(i=0;i<elm.length;i++)
            
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
            {
                
//elm[i].click();
                if(elm[i].checked!=xState)
                elm[i].click();
                
//elm[i].checked=xState;
            }
        }



DataGrid
中的调用方法如下:用红色标记        

<Columns>
                                
<asp:TemplateColumn>
                                    
<HeaderTemplate>
                                        
<asp:CheckBox ID="AllChk" Runat="server" AutoPostBack="False" ToolTip="全选/全不选" onclick="javascript:SelectAll(this);"></asp:CheckBox>
                                    
</HeaderTemplate>
                                    
<ItemTemplate>
                                        
<asp:CheckBox ID="Chk" Runat="server" AutoPostBack="False" onclick="HighlightRow(this)" OnCheckedChanged="Chk_CheckedChanged"></asp:CheckBox>
                                    
</ItemTemplate>
                                  
</asp:TemplateColumn>
                                
<asp:BoundColumn HeaderText="主题" DataField="Topic"></asp:BoundColumn>
                                
<asp:BoundColumn HeaderText="发布人" DataField="Person"></asp:BoundColumn>
                                
<asp:BoundColumn HeaderText="发布时间" DataField="Time"></asp:BoundColumn>
                                
<asp:BoundColumn HeaderText="状态" DataField="State"></asp:BoundColumn>
                            
</Columns>

 

posted on 2008-11-13 01:01  〆o殺殸纨o〆  阅读(209)  评论(0编辑  收藏  举报