Asp.net 模板字段标题文本ASP

Asp.net 模板字段标题文本ASP,asp.net,controltemplate,editmode,headertext,Asp.net,Controltemplate,Editmode,Headertext,我希望HeaderText仅在编辑模式处于活动状态时显示 <asp:TemplateField> <EditItemTemplate> <asp:FileUpload ID="fileUploadControl" runat="server" /> </EditItemTemplate> </asp:TemplateField> 我没有插入模板,我希望标题文本仅在编辑模式下显示一种

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

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


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

一种方法是订阅RowDataBound(假设您使用的是GridView)。检查行是否处于编辑状态,并更新单元格的相应标题文本

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.
    }
}

一种方法是订阅RowDataBound(假设您使用的是GridView)。检查行是否处于编辑状态,并更新单元格的相应标题文本

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.
    }
}
Blake当我单击“编辑”时,您的代码段帮助我成功更改,但当我再次单击“编辑”时,grd.HeaderRow.Cells[0]。文本再次成为默认值,(e.Row.RowState==DataControlRowState.Edit)返回错误Blake当我单击“编辑”时,您的代码段帮助我成功更改,但当我再次单击编辑时,
grd.HeaderRow.Cells[0]。文本
再次成为默认值,因为
(e.Row.RowState==DataControlRowState.Edit)
返回false