File Upload in Gridview with Ajax Modalpopup

Posted by in ASP.NET AJAX category on for Beginner level | Points: 250 | Views : 58247 red flag
Rating: 4 out of 5  
 3 vote(s)

In this article,I will use fileupload control in ajax modal popup to upload file in gridview and the update it.

 Download source code for File Upload in Gridview with Ajax Modalpopup


This article explains using file upload control in Ajax modalpopup extender to upload files in gridview

fileupload in grid with modal popup

Using the code

Take a gridview and bind it with your table and display it on the page.additionally add a link  upload file -

upload link in grid
In .aspx source code

<head id="Head1" runat="server">

<title>File Upload in Gridview with Ajax Modalpopup</title>

<style type="text/css">



background-color: #C0C0C0;

filter: alpha(opacity=80);

opacity: 0.8;

z-index: 10000;





<form id="form1" runat="server">

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">



<table width="100%" align="center">



<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server" AutoGenerateColumns="false">




<asp:LinkButton ID="lnkupload" runat="server" Text="upload resume" OnClick="lnkupclick"></asp:LinkButton>



<asp:BoundField HeaderText="Job ID" DataField="JobID" />

<asp:BoundField HeaderText="Name" DataField="Name" />



<asp:Button ID="btnupe" runat="server" Text="Button" style="display:none;"/>

<asp:ModalPopupExtender ID="ModalPopupExtender1" BackgroundCssClass="modalBackground" runat="server" CancelControlID="btncancel1" TargetControlID="btnupe" PopupControlID="Panel1" >


<asp:Panel ID="Panel1" runat="server" GroupingText="upload resume" BackColor="Orange" style="height:100px;">

<asp:HiddenField ID="HiddenField1" runat="server" Value="" />

<asp:FileUpload ID="flpup" runat="server" />

<asp:Button ID="btnfileupload" runat="server" Text="Upload resume" OnClick="resumeupload" />

<br />

<asp:Button ID="btncancel1" runat="server" Text="cancel" />








//Now in .cs file first bind your gridview with the table and display in the page

//then on link upload click write this code//


protected void lnkupclick(object sender, EventArgs e)


LinkButton lnk = sender as LinkButton;

GridViewRow gvrow = lnk.NamingContainer as GridViewRow;

int id = Int32.Parse(GridView1.DataKeys[gvrow.RowIndex].Value.ToString());

HiddenField1.Value = id.ToString();



//The above code will display modal popup control with file upload control in it.

//now on resume upload button click

protected void resumeupload(Object sender, EventArgs e)


int id = Int32.Parse(HiddenField1.Value);

if (flpup.HasFile)


string filename = Path.GetFileName(flpup.PostedFile.FileName);

flpup.SaveAs(Server.MapPath("~/files/" + filename));//create a folder named 'files' in the solution explorer,the files will be uploaded to this folder //



//your update command e.g :"update tablename set resumepath="'+filename+"' where id="+id;





By this,we can  use modal popup extender to upload files in gridview.
Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Himanshu Pandey
Member Level: Starter
Member Status: Member
Member Since: 6/6/2012 2:28:47 AM
Country: India
Himanshu Pandey
not yet
I am a avid user if this website since i started my career ,always fantasize to post some useful articles into it.I am having 2.5 years of experience in Asp.Net,C#,Sql server,JavaScript and just started m working on WCF and Linq.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)