Click here to Skip to main content
15,900,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
javscript in a gridview



Hi,

I have a gridview, which has two date fields, START_DATE and EXP_DATE. I need to see that the EXP_DATE is not earlier than the START_DATE. Can anyone of you advice me regarding this
Posted
Updated 23-Sep-12 20:36pm
v3
Comments
_Amy 24-Sep-12 1:29am    
Where is your code? What code you are using?
rosren 24-Sep-12 1:50am    
not working:::::::::
function CompareDates()
{

var grid = document.getElementById('<%= GrdvewTax.ClientID %>');
var str1,str2 ,txtRegdte, txtExpdte;
if (grid.rows.length > 0) {

for (var i = 1; i < grid.rows.length; i++) {

str1 = grid.rows[i].cells[3].getElementsByTagName("*")[0].value;
str2 = grid.rows[i].cells[4].getElementsByTagName("*")[0].value;

var str1 = document.getElementById("txtRegdte").value;
var str2 = document.getElementById("txtExpdte").value;

var dt1 = parseInt(str1.substring(0,2),10);
var mon1 = parseInt(str1.substring(3,5),10);
var yr1 = parseInt(str1.substring(6,10),10);
var dt2 = parseInt(str2.substring(0,2),10);
var mon2 = parseInt(str2.substring(3,5),10);
var yr2 = parseInt(str2.substring(6,10),10);
var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);

if(date2 < date1)
{
alert("Expdate cannot be greater than Regdate");
return false;
}
else
{
alert("Submitting ...");
document.form1.submit();
}
Karthik Harve 24-Sep-12 1:33am    
When you want to evaluate the textboxes ? during binding or while updating ?
rosren 24-Sep-12 2:06am    
binding
Karthik Harve 24-Sep-12 2:19am    
you can check in databound event of the gridview.

hi,

check these links.

Get Find control inside of asp.net gridview in rowdatabound event[^]

find the textboxes, compare the values and notify the user using alert message. or else, summarise the messages from all textboxes, store in viewsate temporarily and finaly at last after binding completes, you can notify the user.

hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900