【问题标题】:TemplateField HeaderText ASP模板字段标题文本 ASP
【发布时间】:2011-09-26 15:57:49
【问题描述】:

我希望仅在编辑模式处于活动状态时显示 HeaderText

   <asp:TemplateField>
     <EditItemTemplate>
         <asp:FileUpload ID="fileUploadControl" runat="server" />
     </EditItemTemplate>
   </asp:TemplateField>

我没有插入模板并且我希望仅在编辑模式下显示标题文本

【问题讨论】:

  • Blake 您的代码 sn-p 帮助我在单击编辑时成功更改,但是当我再次单击编辑时 grd.HeaderRow.Cells[0].Text 再次成为默认值,因为 (e.Row.RowState == DataControlRowState.Edit) 返回 false

标签: asp.net controltemplate editmode headertext


【解决方案1】:

这样做的一种方法是订阅 RowDataBound(假设您使用的是 GridView)。检查 Row 是否处于 Edit 状态,并更新 Cell 对应的标题文本。

protected void grd_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowState == DataControlRowState.Edit)
    {
        grd.HeaderRow.Cells[0].Text = "Upload a File"; // Cell 0 in this case may need to be changed to match your Cell.
    }
}

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 2014-09-13
    • 2014-06-06
    • 1970-01-01
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 2013-09-14
    • 1970-01-01
    相关资源
    最近更新 更多