Solved

How to do validation for the grid?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SignalR - getting new data from sql DB 5 79
Visual Studio: built-in keystroke automation 2 46
Re-position the objects 7 95
LINQ - C# to VB convertion 12 45
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

9 Experts available now in Live!

Get 1:1 Help Now