Solved

How to do validation for the grid?

Posted on 2013-01-04
2
202 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now