简体   繁体   中英

gridview find control(file upload) on row editing asp.net

i am creating a web app in which i have a file upload button on gridview,my file upload button is disable by default, on my rowediting, i want to enable my file upload button

this is my aspx page

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

and this is my css page

protected void dgvEdit_RowEditing(object sender, GridViewEditEventArgs e)
        {

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

what i need to do to change fileupload button to enabled=true ?

Use FindControl to find the instance of FileUpload object and update its Enabled property:

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM