日期:2008-11-15 浏览次数:20419 次
aspx文件中加
<script language="javascript">
<!--
//CheckBox全选And反全选
function select_deselectAll (chkVal, idVal)
{
var frm = document.forms[0];
for (i=0; i<frm.length; i++)
{
if (idVal.indexOf ('CheckAll') != -1)
{
if(chkVal == true)
{
frm.elements[i].checked = true;
}
else
{
frm.elements[i].checked = false;
}
}
else if (idVal.indexOf('DeleteThis') != -1)
{
if(frm.elements[i].checked == false)
{
frm.elements[1].checked = false;
}
}
}
}
//-->
</script>
全选<input id="CheckAll" onclick="return select_deselectAll (this.checked, this.id)" tabIndex="0" type="checkbox" title="点击全选或反全选当前页所有信息">
DataGrid中加模板列
<asp:TemplateColumn HeaderText="选定">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox id="chkSelectBox" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
CS文件中操作选定项
foreach (DataGridItem item in DataGrid.Items)
{
if(((CheckBox)item.FindControl("chkSelectBox")).Checked==true)
{
Response.Write (item.Cells[0].Text);
}
}