protected void Button1_Click(object sender, EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { string chk = (row.FindControl("chkdelete") as CheckBox).Text; if (chk.Checked) { string lblid = (row.FindControl("lblid") as Label).Text; SqlCommand comm =new SqlCommand(); comm.CommandText = "delete from tbluser where id=@id"; comm.Connection = conn; comm.Parameters.AddWithValue("@id",int.Parse(lblid.ToString())); conn.Open(); comm.ExecuteNonQuery(); conn.Close(); } } LoadGridView(); }
Error 1 'string' does not contain a definition for 'Checked' C:\Documents and Settings\Harry\My Documents\Visual Studio 2005\deleting data from grid view\Default.aspx.cs 39 21 C:\...\deleting data from grid view\
CheckBox chk = row.FindControl("chkdelete") As CheckBox; if (chk != null) { if (chk.Checked) { // do something } }
Checked
CheckBox chk = ((CheckBox)(row.FindControl("chkdelete"))); if (chk.Checked) { .... }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)