gpt4 book ai didi

c# - 如何计算 asp.net gridview itemtemplate 文本框中 javascript 中两个日期之间的天数

转载 作者:行者123 更新时间:2023-11-29 20:11:50 24 4
gpt4 key购买 nike

我有一个如下图所示的 GridView :

gridview

我在 gridview 的 ItemTemplate 中有文本框。我想计算两个日期之间的天数,并用该值填充最后一个文本框。我可以在 OnTextChanged 事件中做到这一点,但我不想回发。请告诉我如何使用 javascript 函数?(传递文本框值并填充文本框)

                <asp:TemplateField HeaderText="Date of Submission for Xerox review" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10"> 
<EditItemTemplate>
<asp:TextBox ID="IDDtXerox" Text='<%# Eval("Date_Xerox_Review") %>' BorderWidth="1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender3" runat="server" Format="dd/MM/yyyy"

TargetControlID="IDDtXerox" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewIDDtXerox" BorderWidth="1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender4" runat="server" Format="dd/MM/yyyy"

TargetControlID="txtNewIDDtXerox" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblIDDtXerox" Font-Size="Smaller" Text='<%# Bind("Date_Xerox_Review") %>' runat="server"></asp:Label>
</ItemTemplate>

<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date of ID Acceptance/Rejection" HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10">
<EditItemTemplate>
<asp:TextBox ID="IDDtAccRej" Text='<%# Eval("Date_Acceptance_Rejection") %>' BorderWidth="1" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender5" Animated="true" runat="server" Format="dd/MM/yyyy" TargetControlID="IDDtAccRej" />
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewIDDtAccRej" BorderWidth="1" AutoPostBack="true" OnTextChanged="txtNewIDDtAccRej_TextChanged" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender6" runat="server" Format="dd/MM/yyyy" TargetControlID="txtNewIDDtAccRej" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblIDDtAccRej" Font-Size="Smaller" Text='<%# Bind("Date_Acceptance_Rejection") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>

<asp:TemplateField HeaderStyle-BackColor="#1B7AE0" HeaderStyle-Font-Size="10" HeaderText="ID Process Cycle Time (Weekdays)">
<EditItemTemplate>
<asp:TextBox ID="txtProcessTime" BackColor="#E3C5AF" Text='<%# Eval("ID_Process_Time") %>' ReadOnly="true" Width="50px" BorderWidth="1" runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtNewProcessTime" BackColor="#E3C5AF" ReadOnly="true" Width="50px" BorderWidth="1" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblNewProcessTime" Font-Size="Smaller" Text='<%# Bind("ID_Process_Time") %>' runat="server"></asp:Label>
</ItemTemplate>
<HeaderStyle BackColor="#1B7AE0" Font-Size="10pt"></HeaderStyle>
</asp:TemplateField>

请帮忙?

最佳答案

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function calculateDifference()
{
var startDate = document.getElementById("start_date").value;

if(startDate == "")
{
alert("Enter start date");
return;
}
var endDate = document.getElementById("end_date").value;
if(endDate == "")
{
alert("Enter end date");
return;
}

var startDateSplit = startDate.split("/");
var endDateSplit = endDate.split("/");

var stDate = new Date(startDateSplit[2], startDateSplit[0]-1, startDateSplit[1]);
var enDate = new Date(endDateSplit[2], endDateSplit[0]-1, endDateSplit[1]);


var difference = (enDate.getTime() - stDate.getTime())/(1000*60*60*24);

document.getElementById("date_difference").value = difference;
}
</script>
</head>
<body>
<table>
<tr>
<td>
<input type="text" name="start_date" id="start_date" onchange="calculateDifference()" />
</td>
<td>
<input type="text" name="end_date" id="end_date" onchange="calculateDifference()" />
</td>
<td>
<input type="text" name="date_difference" id="date_difference" />
</td>
</tr>
</table>
</body>
</html>

关于c# - 如何计算 asp.net gridview itemtemplate 文本框中 javascript 中两个日期之间的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com