Yes, you can do this. What you want to do is write a JavaScript routine
in your aspx page that looks like this:
function enterDate(e)
{
var d = new Date();
var fullDate = d.getMonth() + "/" + d.getDate() + "/" +
d.getFullYear();
e.value = fullDate;
}
Then in your datagrid, you will need to code up the ItemDataBound event.
First make sure the event is firing for an Item or AlternatingItem
(check e.ItemType for the ListItemType enum). If it is one of these two
kinds of items, then you want to do something like this (I am going to
assume that the check box is in the second cell in the row and a textbox
in the third):
// resolve checkbox and textbox. FindControl takes the name you gave
the control when you
// put in a TemplateColumn.
CheckBox cb = (CheckBox)e.Item.Cells[1].FindControl("chkName");
TextBox tb = (TextBox)e.Item.Cells[2].FindControl("txtName");
// add attribute.
cb.Attributes.Add("onchanged", "enterDate(document.getElementById('" +
tb.UniqueID + "'));");
I am not sure that the right event for the check box is "onchanged".
Look that up and correct it if it is a different event. But this will
configure each checkbox to call the Javascript function and populate the
text box with the current date.
Also, if you use document.getElementById() as I do here, it will only
work in IE. You'll have to resolve the target input tag differently for
other browsers.
John
-----Original Message-----
From: rodchar [mailto:ro*****@discussions.microsoft.com]
Posted At: Monday, August 29, 2005 9:33 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: datagrid checkbox#2
Subject: datagrid checkbox#2
hey all,
is the following even possible?
i have a datagrid with checkboxes on each row, when a user clicks on the
checkbox i'd like to populate one of the fields in the grid with the
current date.
how would i do that?
thanks,
rodchar