Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 文件上载在更新面板内的FormView中不起作用_C#_Asp.net_File Upload - Fatal编程技术网

C# 文件上载在更新面板内的FormView中不起作用

C# 文件上载在更新面板内的FormView中不起作用,c#,asp.net,file-upload,C#,Asp.net,File Upload,我在FormView中有文件上载控制,当我尝试更新FormView时,FormView位于更新面板内。所有操作都正常,但文件上载的图像路径在GridView1行命令后不保存。请帮助我 page.aspx <asp:UpdatePanel ID="upnl1" runat="server"> <ContentTemplate> <asp:FormView ID="FormView1" runat="server"

我在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">
                                    &nbsp;
                                    <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);

        }
    }
protectedvoid imgAddPersonel\u单击(对象发送者,图像单击事件参数)
{
entity.EmployeeId=lovid;
实体。合伙关系=合伙关系;
entity.EmployeeFullName=USEmployee.Des;
添加(实体);
HttpContext.Current.Session[“Listenty”]=Listenty;
datagridbind(参考gd);
USEmployee.LOVId=null;
USEmployee.Des=“”;
txtPartnership.Text=“”;
USEmployee.Focus();
}
}
受保护的void GridView1_row命令(对象发送方,GridViewCommandEventArgs e)
{
如果(e.CommandName==“Delete1”)
{
GridView gd=((GridView)FormView1.FindControl(“GridView1”);
int rowindex=int.Parse(例如,CommandArgument.ToString());
int employeeid=(int)gd.DataKeys[rowindex][“employeeid”];
Listentity=(列表)会话[“Listentity”];
Listentity.RemoveAt(行索引);
会话[“Listenty”]=Listenty;
datagridbind(参考gd);
}
}
受保护的void FormView1_数据绑定(对象发送方、事件参数e)
{
如果(FormView1.CurrentMode==FormViewMode.Insert)
{
ImageButton lb=(ImageButton)FormView1.FindControl(“imgAddPersonel”);
ScriptManager.GetCurrent(第页).RegisterPostBackControl(lb);
}
}

说明

这是
Fileupload
控件通常出现的问题。您的
FileUpload
控件将没有图像路径,因为您的文件上载控件位于
UpdatePanel
中。 运行程序时,
UpdatePanel
将向服务器发送请求,该请求将发送到
ajax
,因此不会触发文件上载控制,也不会按预期工作

回答

您需要删除
FileUpload
控件,并将其放在
UpdatePanel
之外。 然后它就会像预期的那样工作。我希望这些信息对你有用


祝你今天愉快

谢谢。但我知道,因为我的解决方案必须在updatepanelOkay frnd中,所以您需要使用ajax文件上载控件,这肯定会解决您的问题,因为我在文件上载控件方面遇到了很多问题。如果您需要,我可以使用ScriptManager.GetCurrent(页面).RegisterPostBackControl(控件)帮助您编写代码;对于row命令?我有gridview,当我删除任何行文件时,它会添加人员“GridView1”,Upload1无法工作。我想如果我注册LinkButton也许可以解决我的问题