473,785 Members | 2,333 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1228
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.Ite m.Cells[1].FindControl("c hkName");
TextBox tb = (TextBox)e.Item .Cells[2].FindControl("t xtName");

// add attribute.
cb.Attributes.A dd("onchanged" , "enterDate(docu ment.getElement ById('" +
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.getEle mentById() 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.mic rosoft.com]
Posted At: Monday, August 29, 2005 9:33 AM
Posted To: microsoft.publi c.dotnet.framew ork.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
2160
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 these selected fields and allow user to click one or more CheckBox controls to activate this bit on the database table for a required ID. I have already added a template column to the DataGrid and I can get the
4
1520
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 HeaderText="Check In"> <ItemStyle HorizontalAlign="Center" Width="30px"></ItemStyle> <ItemTemplate> <asp:CheckBox id="chkReturn" runat="server" OnCheckedChanged="CheckItIn"></asp:CheckBox>
2
3156
by: Sebi | last post by:
Hello all is it possible to add a checkbox in a DataGrid for Boolean Data? Thanks in advance
0
2406
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 CheckBox Programmatically" in my code. I have changed it to use a OLDDB.DBReader to populate the datagrid and for the databinding. It works perfectly - also when using the edit-mode in the datagrid.
4
1855
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
2279
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 Datagrid that will fire off when the Checkbox is changed? regards /Lars
2
2468
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 checkbox control. where i'm at: i can retrieve a count of the selected checkboxes, but don't know how to get the related id's (in the 1st column).
1
4238
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
3
3150
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 expects a DataGridColumn so I instantiated an object of type TemplateColumn that I had hoped I could add a CheckBox to. I soon discovered that the ItemTemplate property of the TemplateColumn class returned an object that had implemented the...
7
2517
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 implement this, if I am not mistaken, I HAVE TO post the Form first i.e. set the AutoPostBack property of the CheckBox to True. Without posting the Form, I don't think the BackColor of the checked row can be changed using ASP.NET, isn't it? Of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.