如何允许fileuploader在插入时接受多个文件,并允许在gridview中编辑行时仅接受单个文件

时间:2017-09-08 07:28:38

标签: c# asp.net

当我在数据库中插入数据时,我的文件上传器允许多个选择,并且在gridview中显示插入的数据如何在gridview中编辑记录时如何使该文件上载器多次选择为false aspx文件上传代码 -

process.cwd()

.cs代码

<asp:FileUpload ID="fil1" runat="server" multiple="multiple" />

1 个答案:

答案 0 :(得分:0)

在行编辑事件中使用此代码:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    FileUpload fil1 = GridView1.Rows[e.NewEditIndex].FindControl("fil1") as FileUpload;
    fil1.AllowMultiple = false;
}

或者,在行命令事件中使用:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    ImageButton img = sender as ImageButton;
    GridViewRow grv = img.Parent as GridViewRow;
    if (e.CommandName == "mybutton")
    {
        FileUpload fil1 = grv.FindControl("fil1") as FileUpload;
        fil1.AllowMultiple = false;
    }
}

编辑:

尝试从GridViewRow获取:

FileUpload fil1 = (FileUpload)GridView1.Rows[rowIndex].FindControl("fil1");