使用 javaScript 代码如下:
在 aspx 页面中
<script language="javascript" type="text/javascript">
function checkAllOnGrid() {
varintRowCount=document.getElementById('ctl00_ContentPlaceHolder1_hdCount').value;
var chkAll = document.getElementById('ctl00_ContentPlaceHolder1_gvdata_ctl01_chkAll')
var iStartItemIndex = 2;
if (chkAll.checked == true) {
for (i = iStartItemIndex;
i < parseInt(intRowCount) + parseInt(iStartItemIndex) ; i++) {
if (i > 9) {
document.getElementById("ctl00_ContentPlaceHolder1_gvdata_ctl" + i
+ "_" + "ChkAction").checked = true;
} else {
document.getElementById("ctl00_ContentPlaceHolder1_gvdata_ctl0" + i
+ "_" + "ChkAction").checked = true;
}
}
} else {
for (i = iStartItemIndex;
i < parseInt(intRowCount) + parseInt(iStartItemIndex) ; i++) {
if (i > 9) {
document.getElementById("ctl00_ContentPlaceHolder1_gvdata_ctl" + i
+ "_" + "ChkAction").checked = false;
} else {
document.getElementById("ctl00_ContentPlaceHolder1_gvdata_ctl0" + i
+ "_" + "ChkAction").checked = false;
}
}
}
}
function unCheckHeader() {
var chkAll=document.getElementById('ctl00_ContentPlaceHolder1_gvdata_ctl01_chkAll')
if (chkAll.checked == true) { chkAll.checked = false; }
}
</script>
现在使用 ID= hdcount 的文本框和 gridview 中的复选框
现在在 aspx.cs 页面中
protected void fillgrid() {
DataSet ds = new DataSet();
ds = obj.FillGrid();
gvdata.DataSource = ds.Tables[0];
gvdata.DataBind();
hdCount.Text = ds.Tables[0].Rows.Count.ToString();
}
这obj.FillGrid();
是您通过存储过程从后端调用值的方法。