Click here to Skip to main content
15,905,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
 <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-Width="20%" />
                <asp:TemplateField ItemStyle-Width="20%">
                    <ItemTemplate>
                        <asp:TextBox runat="server" ID="NewFiletitle">
                        </asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Title" ItemStyle-Width="20%" />
                <asp:TemplateField ItemStyle-Width="20%">
                    <ItemTemplate>
                        <asp:Button runat="server" ID="btnRemove" Text="Remove" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>--%>
        </asp:GridView>



C#
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 Showing only one row in gridView after File Upload...
Please help...
Posted
Updated 1-Feb-14 1:41am
v4
Comments
[no name] 1-Feb-14 4:01am    
What is your question..??
kedar001 1-Feb-14 4:03am    
updated my question
GridView Not showing Uploaded files

1 solution

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[^]
 
Share this answer
 
Comments
kedar001 1-Feb-14 6:02am    
i tried it before
even if i put controls in item templete and gridview Property AutoGenerateColumns="false"
then also gridview not showing uploaded files
JoCodes 1-Feb-14 6:05am    
But the code you have posted doesnt contain it. Can you show where you have assigned the path+filename to any control?
kedar001 1-Feb-14 6:44am    
i have done one demo. on Page Load bind one datarow to gridView
this datarow bind successfully and shown by gridview
but when i added two more Rows on AjaxFileUpload1_OnUploadComplete() events which are not Updated (gridView Showing One row Only)

is this an issue of postback?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900