在UserControl OnRowUpdate中查找文本框的控件

时间:2014-12-22 06:26:49

标签: c# asp.net gridview webusercontrol

点击更新并触发OnRowUpdate事件后,我发现了一个错误。 在usercontrol中获取文本框值的正确格式是什么?

  

错误55' System.Web.UI.UserControl'不包含的定义   ' PlanID'没有扩展方法' PlanID'接受第一个论点   类型' System.Web.UI.UserControl'可以找到(你错过了吗?   使用指令或程序集引用

protected void grd_Plan_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

            string PlanCode =((UserControl)Grid_Plan.Rows[e.RowIndex].FindControl("ucPlanID")).PlanID;
        }

//usercontrol code behind

public string PlanID
        {
            get
            {
                return txtPlanID.Text;
            }
            set
            {
                txtPlanID.Text = value;
            }
        }

2 个答案:

答案 0 :(得分:1)

试试这个: -

UserControl ucPlanID = (UserControl)Grid_Plan.Rows[e.RowIndex].FindControl("ucPlanID");
if (ucPlanID != null)
{
   string PlanCode = ((TextBox)ucPlanID.FindControl("PlanID")).Text;
}

考虑到,PlanID是文本框的ID。

答案 1 :(得分:0)

您需要使用ClientId访问该控件。请注意,如果是较新的.Net框架版本,您可以将客户端ID模式设置为静态,这将确保客户端ID和您为控件提供的名称相同。

相关问题