• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在gridview显示由AjaxFileUpload上传的文件

用户头像
it1352
帮助1

问题说明

 <div class="demoarea">
        <asp:Label runat="server" ID="myThrobber" Style="display: none;"><img align="absmiddle" alt="" src="uploading.gif"/></asp:Label>
        <ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1"  runat="server" Padding-Bottom="4" Padding-Left="2" Padding-Right="1" Padding-Top="4" ThrobberID="myThrobber" OnClientUploadComplete="onClientUploadComplete"  önUploadComplete="AjaxFileUpload1_OnUploadComplete" MaximumNumberOfFiles="10" AllowedFileTypes="jpg,jpeg" />
        <br />
    </div>
<asp:GridView ID="grdAttachedFiles" runat="server" Width="100%" HorizontalAlign="Center">
            <%--  <Columns>
                <asp:BoundField DataField="FilePath" ItemStyle-  />
                <asp:TemplateField ItemStyle-Width="20%">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="NewFiletitle">
                        </asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Title" ItemStyle-  />
                <asp:TemplateField ItemStyle-Width="20%">
                    <ItemTemplate>
                        <asp:Button runat="server"   Text="Remove" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>--%>
        </asp:GridView>










protected void Page_Load(object sender, EventArgs e)
    {
       
        BindData();
}
 protected void AjaxFileUpload1_OnUploadComplete(object sender, AjaxFileUploadEventArgs file)
    {
        // User can save file to File System, database or in session state
        try
        {
            if (file.ContentType.Contains("jpg") || file.ContentType.Contains("gif")
                || file.ContentType.Contains("png") || file.ContentType.Contains("jpeg"))
            {
                Session["fileContentType_"   file.FileId] = file.ContentType;
                Session["fileContents_"   file.FileId] = file.GetContents();
            }
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("FilePath");
            dt.Columns.Add("Title");
            dt.Columns.Add("Name");

            System.Data.DataRow dtRow;
            dtRow = dt.NewRow();
            dtRow["FilePath"] = "abc";
            dtRow["Title"] = "t1";
            dtRow["Name"] = "n1";
            dt.Rows.Add(dtRow);

            dtRow = dt.NewRow();
            dtRow["FilePath"] = "xyz";
            dtRow["Title"] = "t2";
            dtRow["Name"] = "n2";
            dt.Rows.Add(dtRow);

            grdAttachedFiles.DataSource = dt;
            grdAttachedFiles.DataBind();

            //if (sender._filesInQueue[sender._filesInQueue.length - 1]._isUploaded)
        }
        catch (Exception EX)
        {

        }
    }
private void BindData()
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        dt.Columns.Add("FilePath");
        dt.Columns.Add("Title");
        dt.Columns.Add("Name");

        System.Data.DataRow dtRow;
        dtRow = dt.NewRow();
        dtRow["FilePath"] = "abc";
        dtRow["Title"] = "t1";
        dtRow["Name"] = "n1";
        dt.Rows.Add(dtRow);

        //dtRow = dt.NewRow();
        //dtRow["FilePath"] = "xyz";
        //dtRow["Title"] = "t2";
        //dtRow["Name"] = "n2";
        //dt.Rows.Add(dtRow);

        grdAttachedFiles.DataSource = dt;
        grdAttachedFiles.DataBind();
    }





gridview文件上传后只显示gridView中的一行...

请help ...



gridview Showing only one row in gridView after File Upload...
Please help...

正确答案

#1
你需要在Gridview的ItemTemplate中使用上传文件的FilePath和FileName控件。



参考



http://www.aspsnippets.com/Articles/Upload-files-save-in-folder-and-显示在ASPNet-GridView-with-Download-and-Delete-option.aspx [ ^ ]
You need to have a Control inside the ItemTemplate of the Gridview with the FilePath and FileName of the uploaded file.

Refer

http://www.aspsnippets.com/Articles/Upload-files-save-in-folder-and-display-in-ASPNet-GridView-with-Download-and-Delete-option.aspx[^]

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfieag
系列文章
更多 icon
同类精品
更多 icon
继续加载