Solved

How to do validation for the grid?

Posted on 2013-01-04
2
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

627 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