Click here to Skip to main content
15,886,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have problem in definition in c# code

C#
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();


        }




help me to solve this error the error:- is
VB
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\



thank you
Posted

Look at what you're doing. What I think you want is this:

C#
CheckBox chk = row.FindControl("chkdelete") As CheckBox;
if (chk != null)
{
    if (chk.Checked)
    { 
        // do something
    }
}
 
Share this answer
 
v3
Comments
AmitGajjar 24-Feb-12 7:53am    
Correct , 5+
There is no Checked method or property in System.String[^].
 
Share this answer
 
string does not contains checked property. you have to cast grid view checkbox in asp checkbox control

C#
CheckBox  chk = ((CheckBox)(row.FindControl("chkdelete")));
if (chk.Checked)
{
      ....
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900