Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
i have problem in definition in c# code
 
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
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 24-Feb-12 2:25am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Look at what you're doing. What I think you want is this:
 
CheckBox chk = row.FindControl("chkdelete") As CheckBox;
if (chk != null)
{
    if (chk.Checked)
    { 
        // do something
    }
}
  Permalink  
v3
Comments
amitgajjar at 24-Feb-12 7:53am
   
Correct , 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There is no Checked method or property in System.String[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

string does not contains checked property. you have to cast grid view checkbox in asp checkbox control
 
CheckBox  chk = ((CheckBox)(row.FindControl("chkdelete")));
if (chk.Checked)
{
      ....
}
  Permalink  

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

  Print Answers RSS
0 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 24 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100