“字符串"不包含“已检查"的定义 [英] 'string' does not contain a definition for 'Checked'

查看:77
本文介绍了“字符串"不包含“已检查"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#代码的定义中遇到问题

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

推荐答案

看看你在做什么.我想你想要的是这样的:

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


^ ].


字符串不包含选中的属性.您必须在asp复选框控件中强制转换网格视图复选框

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)
{
      ....
}


这篇关于“字符串"不包含“已检查"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆