GridViewRow row = ((LinkButton)e.CommandSource).NamingContainer as GridViewRow;
In RowDataBound for datakeys
GridView1.DataKeys[e.Row.RowIndex].Value.ToString()
((DataRowView)e.Row.DataItem)["mainid"].ToString()
Blog that contains articles about new technologies related or not with programming. I will describe and solves some problems that I encounter in my career. ASP .NET, AJAX, Javascript, C++, C# and SQL are some of the subjects that will appear.
Showing posts with label checkbox in gridview. Show all posts
Showing posts with label checkbox in gridview. Show all posts
11 September 2012
23 August 2011
checkbox check/uncheck all in gridview
protectedvoid chkHead_CheckedChanged(object sender, EventArgs e)
{
CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkHead");foreach (GridViewRow gr in gv.Rows)
{
CheckBox ch = (CheckBox)gr.Cells[1].FindControl("chkItem");if (chhead.Checked)
ch.Checked =true;
else
ch.Checked =false;
}
}
protectedvoid chkItem_CheckedChanged(object sender, EventArgs e)
{
CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkhead");if (gv.Rows.Count == 1)
{
CheckBox sinch = (CheckBox)gv.Rows[0].FindControl("chkItem");if (sinch.Checked)
chhead.Checked =true;
else
chhead.Checked =false;
}
else
{
foreach (GridViewRow gr in gv.Rows)
{
CheckBox ch = (CheckBox)gr.FindControl("chkItem");if (ch.Checked)
kount++;
}
if (kount == gv.Rows.Count)
chhead.Checked =true;
else
{
kount = 0;
chhead.Checked =false;
}
}
}
{
CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkHead");foreach (GridViewRow gr in gv.Rows)
{
CheckBox ch = (CheckBox)gr.Cells[1].FindControl("chkItem");if (chhead.Checked)
ch.Checked =true;
else
ch.Checked =false;
}
}
protectedvoid chkItem_CheckedChanged(object sender, EventArgs e)
{
CheckBox chhead = (CheckBox)gv.HeaderRow.FindControl("chkhead");if (gv.Rows.Count == 1)
{
CheckBox sinch = (CheckBox)gv.Rows[0].FindControl("chkItem");if (sinch.Checked)
chhead.Checked =true;
else
chhead.Checked =false;
}
else
{
foreach (GridViewRow gr in gv.Rows)
{
CheckBox ch = (CheckBox)gr.FindControl("chkItem");if (ch.Checked)
kount++;
}
if (kount == gv.Rows.Count)
chhead.Checked =true;
else
{
kount = 0;
chhead.Checked =false;
}
}
}
Subscribe to:
Posts (Atom)