AsyncFileUpload和转发器

时间:2014-03-11 19:35:50

标签: asp.net .net-3.5 repeater c#-2.0 asyncfileupload

我有一个asyncfileupload控件和一个转发器,我想用它来显示添加的文件列表。在FileUploadedComplete事件中,我将新文件的名称和大小添加到数据表中,并使用它来绑定转发器。我可以选择一个文件并添加它(SaveAs()),将信息添加到数据表(我可以看到它在那里)但是在调用repeater的databind()后没有任何反应,看不到文件数据。 这就是我所拥有的(淡化版本):

<asp:UpdatePanel runat="server" ID="upnlFU">
    <ContentTemplate>
        <ajaxToolkit:AsyncFileUpload
            runat="server"
            ID="fuAttchedDocs" 
            ThrobberID="myThrobber" 
            UploaderStyle="Modern"
            onuploadedcomplete="fuAttchedDocs_UploadedComplete" 
            onuploadedfileerror="fuAttchedDocs_UploadedFileError" />

        <asp:Repeater runat="server" ID="rptAttachments">
            <HeaderTemplate>
                <table>
                    <tr>
                        <td>File Name</td>
                        <td>File Size</td>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%# Eval("FileName")%></td>
                    <td><%# Eval("FileSize")%></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
    </ContentTemplate>
</asp:UpdatePanel>

代码背后:

DataTable dtAttachments;

protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    {
        dtAttachments = new DataTable();
        dtAttachments.Columns.Add("FileName", Type.GetType("System.String"));
        dtAttachments.Columns.Add("FileSize", Type.GetType("System.Int32"));
        dtAttachments.AcceptChanges();
    }
    else
    {
        dtAttachments = (DataTable)ViewState["Attachments"];
    }
    BindAndSaveAttachmentData();
}

void BindAndSaveAttachmentData()
{
    ViewState["Attachments"] = dtAttachments;
    rptAttachments.DataSource = dtAttachments;
    rptAttachments.DataBind();
}

protected void fuAttchedDocs_UploadedComplete(object sender, AsyncFileUploadEventArgs e)
{
    string sFileName = fuAttchedDocs.FileName;
    string sFileSize = e.FileSize;
    fuAttchedDocs.SaveAs(FilePath.TEMP_FOLDER + sFileName); // Saving to d:\blah\yada temporary folder
    dtAttachments.Rows.Add(new object[] { sFileName, int.Parse(sFileSize) });
    BindAndSaveAttachmentData();
}

文件上传和转发器都在更新面板内。

0 个答案:

没有答案