做了一个功能,全选按钮,对GridView里的记录进行选择
全选的时候,在checkBox里打钩,并且对GridView的某个栏位赋值
我现在直接选单个没有问题,但是按全选只能选中第一个,而且javascript会报错,说缺少对象
javascript是这样写的
function CheckAll(CHECK_FLAG)
{
var objCheckBox;
for(var i=0;i<Form1.length;i++)
{
if(Form1.elements[i].type=="checkbox")
{
objCheckBox=Form1.elements[i];
objCheckBox.checked=CHECK_FLAG;
objCheckBox.onclick();
}
}
}
function changeQty(obj1,value)
{
e = event.srcElement
if(e.checked==true)
{
e = e.parentElement
obj1.value = value;
}
else
{
e = e.parentElement
obj1.value = "";
}
} 后台绑定GridView绑定数据的时候,触发了RowDataBound事件 protected void oGV1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chkSelect = (CheckBox)e.Row.FindControl("chkSelect");
if (chkSelect != null)
{
HtmlInputHidden txt1 = (HtmlInputHidden)e.Row.FindContron("txt1");
TextBox txt2= (TextBox)e.Row.FindControl("txt2");
int nQty = Convert.ToInt32(txt1.Value.Trim());
chkSelect.Attributes.Add("onclick", "changeQty(" + txt2.ClientID + "," + nQty + ")");
}
}
}
全选的时候,在checkBox里打钩,并且对GridView的某个栏位赋值
我现在直接选单个没有问题,但是按全选只能选中第一个,而且javascript会报错,说缺少对象
javascript是这样写的
function CheckAll(CHECK_FLAG)
{
var objCheckBox;
for(var i=0;i<Form1.length;i++)
{
if(Form1.elements[i].type=="checkbox")
{
objCheckBox=Form1.elements[i];
objCheckBox.checked=CHECK_FLAG;
objCheckBox.onclick();
}
}
}
function changeQty(obj1,value)
{
e = event.srcElement
if(e.checked==true)
{
e = e.parentElement
obj1.value = value;
}
else
{
e = e.parentElement
obj1.value = "";
}
} 后台绑定GridView绑定数据的时候,触发了RowDataBound事件 protected void oGV1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox chkSelect = (CheckBox)e.Row.FindControl("chkSelect");
if (chkSelect != null)
{
HtmlInputHidden txt1 = (HtmlInputHidden)e.Row.FindContron("txt1");
TextBox txt2= (TextBox)e.Row.FindControl("txt2");
int nQty = Convert.ToInt32(txt1.Value.Trim());
chkSelect.Attributes.Add("onclick", "changeQty(" + txt2.ClientID + "," + nQty + ")");
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货