在更新面板的FormView中,文件上传不起作用
本文关键字:文件 不起作用 FormView 更新 | 更新日期: 2023-09-27 17:50:40
我在FormView中有文件上传控制,当我尝试更新FormView时,FormView在更新面板内,但图像路径从fileupload不保存GridView1行命令后请帮助我…
page.aspx
<asp:UpdatePanel ID="upnl1" runat="server">
<ContentTemplate>
<asp:FormView ID="FormView1" runat="server" DataSourceID="ObjectDataSource1" Width="20px">
<InsertItemTemplate>
<table>
<tr>
<td style="border-style: dashed dashed dashed none; dashedborder-style: none dashed none dashed;
border-width: thin; border-color: #000000;">
<asp:Label ID="Label14" runat="server" Text="user" BorderStyle="None"></asp:Label>
</td>
<td style="border-style: dashed none dashed none; border-width: thin; border-color: #000000;">
<uc1:Employee ID="UCEmployee" runat="server" />
</td>
<td style="border-style: dashed none dashed none; border-width: thin; border-color: #000000;">
<asp:Label ID="Label15" runat="server" Text="percent"></asp:Label>
</td>
<td style="border-style: dashed none dashed dashed; border-width: thin; border-color: #000000;">
<asp:TextBox ID="txtPartnership" runat="server" Width="60px"></asp:TextBox>
<asp:ImageButton ID="imgAddPersonel" runat="server" ImageUrl="~/App_Themes/images/icons/add.gif"
OnClick="imgAddPersonel_Click" />
</td>
</tr>
<tr>
<td style="border-style: none dashed dashed dashed; border-width: thin; border-color: #000000;"
colspan="4">
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">
</asp:GridView>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label20" runat="server" Text="attachment" ></asp:Label>
</td>
<td colspan="3">
<asp:FileUpload ID="FileUpload1" runat="server"/>
</td>
</tr>
</table>
</InsertItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:FormView>
cs文件
protected void imgAddPersonel_Click(object sender, ImageClickEventArgs e)
{
entity.EmployeeId = lovid;
entity.Partnership = Partnership;
entity.EmployeeFullName = USEmployee.Des;
Listentity.Add(entity);
HttpContext.Current.Session["Listentity"] = Listentity;
datagridbind(ref gd);
USEmployee.LOVId = null;
USEmployee.Des = "";
txtPartnership.Text = "";
USEmployee.Focus();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete1")
{
GridView gd = ((GridView)FormView1.FindControl("GridView1"));
int rowindex = int.Parse(e.CommandArgument.ToString());
int employeeid = (int)gd.DataKeys[rowindex]["EmployeeId"];
Listentity = (List<SuggestionEmployee>)Session["Listentity"];
Listentity.RemoveAt(rowindex);
Session["Listentity"] = Listentity;
datagridbind(ref gd);
}
}
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
ImageButton lb = (ImageButton)FormView1.FindControl("imgAddPersonel");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb);
}
}
解释
这是Fileupload
控制通常发生的问题。您的FileUpload
控件将没有镜像路径,因为您的文件上传控件在UpdatePanel
中。当您运行程序时,您的UpdatePanel
将向服务器发送请求,该请求将被发送到ajax
,因此文件上传控制将不会触发,也不会像预期的那样工作。
您需要删除FileUpload
控件并将其放在UpdatePanel
之外。然后它会像预期的那样工作。我希望这些信息对你有用。