[英]How can I get dates inserted whenever a checkbox is checked?
I have this on markup: 我在标记上有这个:
<asp:TemplateField HeaderText="Date Printed">
<ItemTemplate>
<asp:Label ID="lblMessage" style ="font-weight:bold; " runat="server" CssClass="style26"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Then this code behind 然后这段代码后面
For Each r As GridViewRow In gridView1.Rows
If CType(r.Cells(0).FindControl("myrec"), CheckBox).Checked Then
lblMessaget.Text = DateTime.Now.ToString("dd/MM/yyyy")
End If
Next
All I am really trying to do is whenever a user clicks a checkbox to check it and clicks the Print Checked Item box, today's date is inserted into the Date Printed column of the row of the checked box. 我真正想做的就是,只要用户单击复选框以选中它,然后单击“打印已检查项目”框,今天的日期就会插入到该复选框行的“打印日期”列中。
I am doing something stupid and that's why this is not working. 我正在做一些愚蠢的事情,这就是为什么这不起作用。
Any help is greatly appreciated. 任何帮助是极大的赞赏。
Although I am trying to do this with vb.net or c#, if anyone can help me do it with JavaScript, that would be great also. 尽管我正在尝试使用vb.net或c#进行此操作,但是如果有人可以使用JavaScript来帮助我完成该操作,那也很好。
<script type="text/javascript">
function CheckBox_Click() {
$('#' + '<%=gridView1.ClientID %>' + ' tr:has(:checkbox:checked) td:nth-child(3) span').each(function () {
$(this).attr("innerHTML", new Date());
});
}
</script>
i think you need to make sure you have the right label. 我认为您需要确保您拥有正确的标签。 lblMessaget
is always assigned, but you say: lblMessaget
总是被分配,但是您说:
...date is inserted into the Date Printed column of the row of the checked box. ...日期将插入到复选框行的“打印日期”列中。
So you also need: 因此,您还需要:
CType(r.Cells(0).FindControl("row-specific-label"), Label).Text = DateTime.Now.ToString( "dd.MM.yyyy" );
// Edit: //编辑:
You need to make sure that you use the right index for the cell. 您需要确保为单元格使用正确的索引。 You need the cell of the label whatever this is. 无论这是什么,您都需要标签的单元格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.