【问题标题】:How to keep the textbox inside of a cell from gridview, in a postback如何在回发中将文本框保留在gridview的单元格内
【发布时间】:2023-04-01 06:10:01
【问题描述】:

我的问题如下,当您第一次加载页面时,您会看到单元格内的文本框带有红色背景,但是当有回发时,单元格内的文本框会丢失。

加载方法填充我的gridview。

想法是当列颜色为红色时,我需要创建一个文本框并将文本框的背景设置为红色;

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                Load();
            }
           

        }
 protected void GvCriticidad_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
      if (e.Row.Cells[2].Text == "RED") {
          System.Web.UI.WebControls.TextBox txt = new System.Web.UI.WebControls.TextBox();
          txt.Enabled = false;
          txt.Width = 35;
          txt.Height = 30;
          txt.BackColor = ColorTranslator.FromHtml("#FD0707");
          e.Row.Cells[2].Text = "";
          e.Row.Cells[2].Controls.Add(txt);
                
        }
      
     }


 }

【问题讨论】:

    标签: c# webforms postback code-behind


    【解决方案1】:

    您在回发时做什么?您是否要求重新加载网格?根据您共享的内容,文本框不会显示,因为那里发生了回发,因为没有调用 Load() 方法。删除 !PostBack 检查并每次调用 load 是否可以解决您的问题?

     protected void Page_Load(object sender, EventArgs e)
        {
           Load();
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-18
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多