感谢您的所有帮助.. 最后我得到了脚本工作。但它很长。我把它贴在下面供任何人使用。如果有人不清楚。请随时询问,以便我可以告诉我我做了什么。
<script type="text/javascript" language="javascript">
function req_mac_month(numbers,fromDate,toDate,mcMonth)
{
//alert("Executed");
var reqnum=document.getElementById(numbers).value;
var sdate=document.getElementById(fromDate).value;
var edate=document.getElementById(toDate).value;
//var diff=DisplayTo.getMonth() - DisplayFrom.getMonth() + (12 * (DisplayTo.getFullYear() - DisplayFrom.getFullYear()));
//var diff=Math.ceil((DisplayTo.getTime()-DisplayFrom.getTime())/(1000*60*60*24));
var day1, day2;
var month1, month2;
var year1, year2;
//var noofmonths;
day1 = sdate.substring(0, sdate.indexOf("-"));
month1 = sdate.substring(sdate.indexOf("-") + 1, sdate.lastIndexOf("-"));
year1 = sdate.substring(sdate.lastIndexOf("-") + 1, sdate.length);
day2 = edate.substring(0, edate.indexOf("-"));
month2 = edate.substring(edate.indexOf("-") + 1, edate.lastIndexOf("-"));
year2 = edate.substring(edate.lastIndexOf("-") + 1, edate.length);
date1 = year1 + "/" + month1 + "/" + day1;
date2 = year2 + "/" + month2 + "/" + day2;
firstDate = Date.parse(date1)
secondDate = Date.parse(date2)
msPerDay = 24 * 60 * 60 * 1000
dbd = trunc(((Math.round(((secondDate.valueOf() - firstDate.valueOf()) / msPerDay) + 1))/30),4);
reqmcmonthtotal = dbd * reqnum ;
document.getElementById(mcMonth).value= reqmcmonthtotal;
return true;
}
</script>
在后面的代码中......,
TextBox rnum = grvps.FooterRow.FindControl("Ftxteditreqnum") as TextBox;
TextBox fromDate = grvps.FooterRow.FindControl("txtFromDate") as TextBox;
TextBox toDate = grvps.FooterRow.FindControl("txtEndDate") as TextBox;
TextBox mcMonth = grvps.FooterRow.FindControl("Ftxteditreqmcmth") as TextBox;
string req_mac_month = string.Format("return req_mac_month('{0}','{1}','{2}','{3}');", rnum.ClientID, fromDate.ClientID, toDate.ClientID, mcMonth.ClientID);
rnum.Attributes.Add("onchange", req_mac_month);
fromDate.Attributes.Add("onchange", req_mac_month);
toDate.Attributes.Add("onchange", req_mac_month);