Showing posts with label checkbox in gridview. Show all posts
Showing posts with label checkbox in gridview. Show all posts

11 September 2012

How to get the current row in the grid view rowcommand event

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()

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;
}
}
}