2017-02-13 68 views
1

我正在創建一個web應用程序,我在gridview上有一個文件上傳按鈕,我的文件上傳按鈕被默認禁用,在我的rowediting上,我想啓用我的文件上傳按鈕gridview查找控件(文件上傳)行編輯asp.net

這是我的aspx頁面

<asp:TemplateField HeaderText="Attachtment"> 
           <ItemTemplate> 
            <%--<asp:LinkButton ID="lnkDownload" Text="Download" CommandArgument='<%# Eval("FileData") %>' runat="server" OnClick="lnkDownload_Click"></asp:LinkButton>--%> 
            <asp:FileUpload ID="fpTask" cssstyle="width:100%; margin-left:-10px;" Enabled="false" runat="server" /> 

            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationExpression="([a-zA-Z0-9\s_\\.$&*#@()+\-:])+(.doc|.docx|.pdf|.jpg|.png|.jpeg|.xls|.xlsx|.txt|.gif)$" 
             ControlToValidate="fpTask" runat="server" ForeColor="Red" ErrorMessage="selected file is not valid" 
             Display="Dynamic" /> 
           </ItemTemplate> 
          </asp:TemplateField> 

,這是我的CSS頁面

protected void dgvEdit_RowEditing(object sender, GridViewEditEventArgs e) 
     { 

      dgvEdit.EditIndex = e.NewEditIndex; 
      LoadGridTask("EDIT", Session["CurrentUser"].ToString(), Session["TaskID"].ToString()); 
     } 

什麼,我需要做的更改文件上傳按鈕enabled=true

回答

0

使用FindControl找到FileUpload對象的實例,並更新其Enabled屬性:

protected void dgvEdit_RowEditing(object sender, GridViewEditEventArgs e) 
{ 

    dgvEdit.EditIndex = e.NewEditIndex; 

    FileUpload fpTask =(FileUpload) dgvEdit.Rows[e.RowIndex].FindControl("fpTask"); 
    fpTask.Enabled = true; 

    LoadGridTask("EDIT", Session["CurrentUser"].ToString(), Session["TaskID"].ToString()); 
}