我在FormView中有文件上传控件,并且当我尝试更新FormView时,FormView在更新面板内,但是一切正常,但是文件上载后的图像路径不会在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);
}
}
答案 0 :(得分:1)
说明
这是Fileupload
控件通常会出现的问题。您的FileUpload
控件将没有图像路径,因为您的文件上传控件位于UpdatePanel
。
当您运行程序时,UpdatePanel
将向服务器发送请求,并且该请求将发送到ajax
,因此文件上载控件不会被触发,也无法按预期工作。
<强> ANSWER 强>
您需要移除FileUpload
控件并将其放在UpdatePanel
旁边。
然后它将按预期工作。我希望这些信息对您有用。
度过美好的一天。