473,323 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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
Nov 19 '05 #1
1 1201
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Just D | last post by:
Hi All, Does anybody know how to write the following code? I have a database table with a few columns including: ID , "Task" , ForceRun . I need to show the DataGrid on the ASPX page with...
4
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn...
2
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
by: mike | last post by:
Hi there: I've read an excellent "how to"-article by Microsoft (no. 306227) - partly cited cited at the end of this email). I have implemented the code related to the part "How to Add a...
4
by: Mike | last post by:
Hi, Is there a possibility to have one of the Web Control Datagrid's column as a Calendar when editing data? Any resources on this subject? Thanks Mike
7
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
7
by: rn5a | last post by:
The first column of a DataGrid has a CheckBox for all the rows. I want that when users check a CheckBox, the BackColor of that entire row in the DataGrid should change to a different color. To...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.