【问题标题】:Assign the value of a templatefield on gridview to variable将gridview上模板字段的值分配给变量
【发布时间】:2013-03-13 20:08:23
【问题描述】:

我知道如何在 RowDataBound 事件中获取 templatefield 的值:

Control ctrl = e.Row.FindControl("Drop_Responsaveis");  
DropDownList ddl = ctrl as DropDownList;
ddl.items.add(something);

但我需要在 button_Click 事件中获得它的价值...我该怎么做?

@Siz S 回答的解决方案

foreach (GridViewRow gvr in GridView1.Rows)
   {
     string str = ""
     Control ctrl = gvr.FindControl("Drop_Responsaveis");
     if (ctrl != null)
        {
           DropDownList ddl = ctrl as DropDownList;
           str= ddl.SelectedItem.ToString();
        }
    }

【问题讨论】:

  • 为什么有人试图关闭我的问题而不发表评论说明原因...

标签: asp.net gridview templatefield


【解决方案1】:

你可以得到gridview TemplateField控件为

foreach (GridViewRow row in yourGrid.Rows)
{
     Control ctrl = row.FindControl("Drop_Responsaveis");
     DropDownList ddl = ctrl as DropDownList;
     ddl.items.add(something);
 }

【讨论】:

  • 工作完美的男人!我用解决方案更新了我的问题,再次感谢您Siz S
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 2020-04-07
  • 2019-08-31
相关资源
最近更新 更多