如何留住视图状态在GRIDVIEW创建的动态控件 [英] how to retain viewstate for the dynamic controls created in GRIDVIEW

查看:91
本文介绍了如何留住视图状态在GRIDVIEW创建的动态控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GridView控件创建动态文本框onRowCreated事件,但是当我尝试的FindControl我得到空

在这里是怎么了......董

 保护无效gvORg_RowCreated(对象发件人,GridViewRowEventArgs E)
{
   如果((e.Row.RowState ==(DataControlRowState.Edit | DataControlRowState.Alternate))||(e.Row.RowState == DataControlRowState.Edit))
    {
      如果(e.Row.RowType == DataControlRowType.DataRow)
         {
              txBox txtReg =新的TextBox();
              txtReg.ID =_registration+ e.Row.RowIndex + rowId.ToString();
              txtReg.Text = reg.RegistrationToken;
              e.Row.Cells [7] .Controls.Add(txtReg);
         }
    }
}
  保护无效gvOrg_RowUpdating(对象发件人,GridViewUpdateEventArgs E)
        {
            .....
            ....
             文本框_registration1 = gvOrg.Rows [e.RowIndex] .Cells [7] .FindControl(_登记+ e.RowIndex + ROWID)的文本框;
        }


解决方案

我能解决我的问题的这里

i am creating dynamic textbox onRowCreated event in gridview control, however when i try to findcontrol i get null

here is how i am dong...

protected void gvORg_RowCreated(object sender, GridViewRowEventArgs e)
{
   if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
    {
      if (e.Row.RowType == DataControlRowType.DataRow)
         {
              txBox txtReg = new TextBox();
              txtReg.ID = "_registration" + e.Row.RowIndex + rowId.ToString();
              txtReg.Text = reg.RegistrationToken;
              e.Row.Cells[7].Controls.Add(txtReg);
         }
    }
}


  protected void gvOrg_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            .....
            ....
             TextBox _registration1 = gvOrg.Rows[e.RowIndex].Cells[7].FindControl("_registration" + e.RowIndex + rowId) as TextBox;   
        }

解决方案

i able to fix my problem here

这篇关于如何留住视图状态在GRIDVIEW创建的动态控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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