I want get the rows I selected from gridview use a checkbox.
The checkbox is like this!
try this:
protected void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
GridViewRow row = (GridViewRow)checkbox.NamingContainer;
if (checkbox.Checked == true) {
row.BackColor = System.Drawing.Color.Red;
mygridview.Columns(0).Visible = false;
}
}
You can loop through the GridView rows and use FindControl to retrieve the Checkbox and then get the IsChecked property on them.
foreach (GridViewRow row in grid.Rows)
{
CheckBox check = (CheckBox)row.FindControl("CheckboxID");
if (CheckBox1.Checked)
{
...
}
}