Validate FileUpload control in grid view...

Madhu.b.rokkam
Posted by in ASP.NET category on for Beginner level | Points: 250 | Views : 11430 red flag
Rating: 5 out of 5  
 1 vote(s)

This article deals with validating the FileUpload control which is inside a GridView control.


 Download source code for Validate FileUpload control in grid view...

Introduction

As per the requirement of one of the DNF friend's, I am presenting this article in which we will be validating a file upload control which is inside a grid view control.

Let us take a scenario where we have a gridview in that we have a checkbox column and one file upload controls column and a common submit button outside gridview. And in this if we check a rows checkbox and we need to check whether the file upload control contains any value or not. if checkbox is checked and file upload control contains values then we will do some task and if not means we will alert a message.

So lets start with our sample...

Step1 - Open Visual studio and add new website project.

Step 2 – Rightclick on the project -> add new item -> Select xml file -> Name it as Data1.xml we are simply add this to populate with the serial numbers in the grid, and this you can achieve in any other way you like.

Step 3 - Add a new Gridview to the aspx page and add two template fields one for the checkbox and one for the fileupload control. And design as shown below

Step 4 - The ASPX source will have the gridview content as below

Step 5 - Load the data from xml to grid view on page load

Step 6 - On RowDataBound of the grid view we need to register client side array declaration for the checkbox and fileupload control respectively.

Step 7 - Now we have to add our validation logic into a javascript function

Step 8 - Build and run your application. Select a checkbox without selecting a file and click on check button. You will a popup message as shown below. If file is selected then the page posts back and you need to add the logic for storing data into DB

Thats it!

Hope you like this article, let me know your thoughts and comments.

Page copy protected against web site content infringement by Copyscape

About the Author

Madhu.b.rokkam
Full Name: Madhu Rokkam
Member Level: Bronze
Member Status: Member,MVP
Member Since: 1/13/2011 3:13:20 PM
Country: India
Thanks and Regards Madhu
http://www.dotnetfunda.com

Login to vote for this post.

Comments or Responses

Posted by: petajhansi-9330 on: 3/7/2011 | Points: 25
Its Good
Posted by: Madhu.b.rokkam on: 3/7/2011 | Points: 25
Thanks for your comments ...
Posted by: Tripati_tutu on: 3/12/2011 | Points: 25
good one....
Posted by: Theramkumar on: 4/1/2011 | Points: 25
Hi, thanks for your coding....

I have one doubt, where can I place the java script coding?

Pls reply me?
Posted by: Sashys on: 7/17/2011 | Points: 25
Hi Theramkumar,
We need to place the javascript in the head section of the aspx file. So this validate function will be called when the button is clicked.

Hi Madhu,

The Article is simply nice. Will help most of them..


Login to post response

Comment using Facebook(Author doesn't get notification)