【问题标题】:how to get a value from templateField on gridview如何从gridview中的templateField获取值
【发布时间】:2018-06-07 22:23:39
【问题描述】:

如何从gridview上的templateField获取值或文本

<asp:TemplateField HeaderText ="Format">
    <ItemTemplate>
      <asp:Label ID="Format" runat="server" 
       Text='<%#GetFormatText(DataBinder.Eval(Container.DataItem, ("Format")))%>'> 
      </asp:Label>
    </ItemTemplate>
</asp:TemplateField>

grvRow.Cells[4] 的值始终为空。

drpFormat.SelectedValue = grvRow.Cells[4].Text;

【问题讨论】:

    标签: c# asp.net gridview webforms


    【解决方案1】:

    您必须使用 FindControl 来获取模板字段中的标签

      Label lblname = (Label)grvRow.Cells[4].FindControl("Format");
      drpFormat.SelectedValue= lblname.Text;
    

    【讨论】:

    • 谢谢朋友 Label formatText = (Label)grvRow.FindControl("FormatText");
    【解决方案2】:

    你也可以这样试试

    System.Web.UI.WebControls.Label lbl = ((System.Web.UI.WebControls.Label)e.Row.Cells[4].FindControl("Format"));
    string SelectedData =lbl.text;
    

    【讨论】:

      猜你喜欢
      • 2013-10-09
      • 1970-01-01
      • 2011-12-02
      • 2016-03-03
      • 1970-01-01
      • 2018-10-11
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多