Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 19160 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET AJAX > File Upload in Gridview with Ajax Modalpopup

File Upload in Gridview with Ajax Modalpopup

3 vote(s)
Rating: 4 out of 5
Article posted by Me_Himanshu on 6/14/2012 | Views: 9673 | Category: ASP.NET AJAX | Level: Beginner | Points: 250 red flag

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

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">

.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.
Advertisements

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

Experience:1 year(s)
Home page:not yet
Member since:Wednesday, June 06, 2012
Level:Starter
Status: [Member]
Biography: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 1.5 years of experience in Asp.Net,C#,Sql server,JavaScript and just started m working on WCF and Linq.
>> Write Response - Respond to this post and get points
Related Posts

In this article we will try to understand the 4 important steps to consume web service directly in Ajax. In this sample we will create a simple customer combo box as shown in the figure below. This customer combo box will be filled by calling the web service methods directly of the customer web service.

An Ajax DLL is used to call server side method asynchronously without processing the whole page life cycle.

In this article, I will show you how to create a multi-select in an ASP.net page. I will keep this article short and sweet so you can just use the code in your applications. Previously i refer many codes about multiselect dropdown but i found all are little complex to implement. So i decided to try it in my own. Lets see how i implement this.

In this article we will see how to check whether username exists in database or not without refreshing the page using ajax updatepanel control.

In this article explains you how to display an image for textbox server control while on focus the control.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/18/2013 2:31:18 AM