selecting checkbox insiding gridview control in asp.net
stringBuilder name=new stringBuilder();
//select checkbox from gridview control
for (int i = 0; i < GridView1.Rows.Count; i++){
GridViewRow row_names = GridView1.Rows[i];
bool isChecked = ((CheckBox) row_names.FindControl(“chkSelect”)).Checked;
if (isChecked)
{
str.Append(GridView1.Rows[i].Cells[2].Text);
}
}
//Results
Response.Write(str.ToString());
<HeaderTemplate>
<input id=”cheackall” onclick=”javascript:selectcheckbox(this);” runat=”server” type=”checkbox” />
</HeaderTemplate>
<script language=javascript>
function selectcheckbox(chk){
var item1 = Chk.children;
var theBox=(Chk.type==“checkbox”)?Chk:Chk.children.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;
}
}
</script>
Posted By: V.Mahesh
Posted by Mahesh ( Tryangled )