![]()
Article posted by
Me_Himanshu on 6/14/2012 | Views: 9673 | Category:
ASP.NET AJAX | Level: Beginner |
Points: 250
If you found
plagiarised (copied) or inappropriate content,
please
let us know the original source along with your correct email id (to communicate) for further action.
Advertisements
Advertisements
In this article,I will use fileupload control in ajax modal popup to upload file in gridview and the update it.
Download
Download source code for File Upload in Gridview with Ajax Modalpopup
Introduction
This article explains using file upload control in Ajax modalpopup extender to upload files in gridview
Using the code
Take a gridview and bind it with your table and display it on the page.additionally add a link upload file -
In .aspx source code
<
head id="Head1" runat="server">
<title>File Upload in Gridview with Ajax Modalpopup</title><style type="text/css">
.modalBackground{
background-color: #C0C0C0;filter: alpha(opacity=80);opacity: 0.8;z-index: 10000;}
</style></
head><
body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager><div>
<table width="100%" align="center">
<tr>
<td>
<asp:GridView ID="GridView1" DataKeyNames="ID" runat="server" AutoGenerateColumns="false">
<Columns><asp:TemplateField><ItemTemplate><asp:LinkButton ID="lnkupload" runat="server" Text="upload resume" OnClick="lnkupclick"></asp:LinkButton></ItemTemplate></asp:TemplateField><asp:BoundField HeaderText="Job ID" DataField="JobID" /><asp:BoundField HeaderText="Name" DataField="Name" /></Columns></asp:GridView><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:ModalPopupExtender><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" /></asp:Panel></td></tr></table></div></form></
body>
//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();
ModalPopupExtender1.Show();
}
//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 //con.Open();
{
//your update command e.g :"update tablename set resumepath="'+filename+"' where id="+id;}
}
}


Conclusion
By this,we can use modal popup extender to upload files in gridview.
If you like this article, subscribe to our
RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.
Found interesting? Add this to: