在方法中找不到gridview控件的错误 [英] Error to find control of gridview in method

查看:82
本文介绍了在方法中找不到gridview控件的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在方法中找到标签控制值

此处的代码

i have problem to find label control value in method

code here

private void grdProjectBind()
        {
            int userClientID = 0;
            Project ObjProject = new Project();
            try
            {

                foreach (GridView row in grdClient.Rows)
                {
                     userClientID = Convert.ToInt32(((Label)row.FindControl("lbUserClientID")).Text);//error here
                
                }

                   // int userClientID = Convert.ToInt32(((Label) .FindControl("lbUserClientID")).Text);


                ObjProject.UserClientID = userClientID;

                    DataSet ds = new DataSet();
                    ds = ObjProject.GetProjectList();
                    if (ds.Tables[0].Rows.Count != 0)
                    {
                        grdProject.DataSource = ds;
                        grdProject.DataBind();
                        btnAddProject.Visible = false;
                    }
                    else
                    {
                        grdProject.DataBind();
                        btnAddProject.Visible = true;

                    }
                }
            
            catch (Exception)
            {

                throw;
            }
            finally
            {
                ObjProject = null;
            }
        
        
        }



错误说明:无法将类型为"System.Web.UI.WebControls.GridViewRow"的对象转换为类型为"System.Web.UI.WebControls.GridView"的对象.


感谢



Explaination of error: Unable to cast object of type ''System.Web.UI.WebControls.GridViewRow'' to type ''System.Web.UI.WebControls.GridView''.


thanks

推荐答案



您的例外是告诉您出了什么问题.
您需要在for循环中使用GridViewRow而不是GridView:foreach(grdClient.Rows中的GridViewRow行)

grdClient.Rows是GridViewRow对象的集合.在此处检查
Hi,

Your exception is telling you whats wrong.
You need to use GridViewRow Not GridView in for loop: foreach (GridViewRow row in grdClient.Rows)

grdClient.Rows is a collection of GridViewRow objects. Check here[^].


foreach (GridView row in grdClient.Rows)



检查一下:



Check it:

foreach (GridViewRow row in grdClient.Rows)


这篇关于在方法中找不到gridview控件的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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