Solved

How to do validation for the grid?

Posted on 2013-01-04
2
207 Views
Last Modified: 2013-01-05
Hi,

Pls find the attached image.

I have 2 dropdowns (NewsSector, NewsSectorType). when i select values from these 2 dropdowns and click on Add button, it will add rows to grid. Here i need to do validation ie if user is trying to add the same row which is alreday existed then it has to show pop up message that "Please select another NewsSector and NewsSectorType as it is already existed".

can we do this validation in client side? If so, how?


Thanks,
validation.jpg
0
Comment
Question by:swathi111
2 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 38745025
var gv = document.getElementById("gridViewID");

var exists = false;
var ddlNewsSector = document.getElementById("ddlNewsSector");
var ddlNewsSectorType = document.getElementById("ddlNewsSectorType");
for(var i = 1; i< gv.rows.length; i++)
{
      var  tr = gv.rows[i];
      var NewsSector = tr.cells[0];
      var NewsSectorType = tr.cells[1];
      
      if(NewsSector.innerHTML == ddlNewsSector.Items[ddlNewsSector.SelectedIndex].value
            && NewsSectorType.innerHTML == ddlNewsSectorType.Items[ddlNewsSectorType.SelectedIndex].value
        )
        {
            exists = true;
            break;
        }
}

if(exists == true)
{
      alert("Record already exists");
      return false;
}
else
       return true;

Open in new window

0
 

Author Comment

by:swathi111
ID: 38747624
I tried this. Its working perfect. Thanks for your code.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question