> I've a datagrid in my application, template column contains a check box
> plus more columns from my table. when user clicks checkbox i call
> javascript
> to make sure at any time one checkbox is clicked. it works fine.
Presumably, you are fetching the collection of checkbox input controls using
something like document.getElementsByTagName...? This is fairly simple
because you don't need to know anything about each checkbox except whether
it's checked or not...
> Now i'd like to check another bound column datetime, when user click
> checkbox i want to check whether the date is in current month and year, if
> not just a alert to user to tell you cannot select this because not in
> current month and date.
This, however, is a little trickier because you now need to evaluate the
contents of a "specific" control. Added to that, it could be any control
which has a corresponding checkbox.
So, what follows is a technique for doing this - I'm assuming since you're
already doing some client-side JavaScript programming you can figure out the
specifics...
Firstly, you need to create a JavaScript function which will accept a DOM
object as an argument - this will be the textbox whose value property
contains the date you need to evaluate. The function will create a Date
object as the current date and then create another Date object from the
value property of the textbox argument. You will compare the two date
objects as required and return true or false as necessary:
http://www.google.co.uk/search?sourceid=navclient&aq=t&hl=en-GB&ie=UTF-8&rlz=1T4
GGIH_en-GBGB220GB220&q=JavaScript+date+validation
Call this something like:
function checkDate(DateTextBox)
{
}
Secondly, you need to tell your checkboxes to call this client-side
JavaScript function in response to their click event:
http://www.google.co.uk/search?hl=en&rlz=1T4GGIH_en-GBGB220GB220&q=JavaScript+ch
eckbox+click&meta=
To do this, you need to use the DataGrid's RowDataBound event:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowd
atabound.aspx
For each row being bound to the DataGrid, you will need to find firstly the
TextBox which will contain the date and then the CheckBox to which you will
use the Attributes.Add method to tell it to call the JavaScript function
when it's clicked. E.g. if the CheckBox is in the first cell in each row and
the TextBox is in the second cell in each row:
e.Row.Cells[0].FindControl("MyCheckBox").Attributes.Add("onclick", "return
checkDate(e.Row.Cells[1].FindControl("DateTextBox").ClientID);");
N.B. their may be some syntactical errors in the above as I've just written
it from memory, but that's certainly how I'd do it...
HTH,

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Ganesh - 05 Jul 2007 11:43 GMT
> > I've a datagrid in my application, template column contains a check box
> > plus more columns from my table. when user clicks checkbox i call
[quoted text clipped - 55 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Hi Mark,
Thanks a lot, that was really useful. I'll try this now.
Mark Rae [MVP] - 05 Jul 2007 11:56 GMT
> Thanks a lot, that was really useful. I'll try this now.
No worries.
Incidentally, is there any reason that you're using DataGrid and not
GridView? Are you still using VS.NET 2003...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Ganesh - 05 Jul 2007 18:28 GMT
Yes we do use vs.net 2003 . Company had already started developement before
2005 release. still they want to use the same one. I don't see they have any
plan to update at the moment.
Thanks
>> Thanks a lot, that was really useful. I'll try this now.
>
> No worries.
>
> Incidentally, is there any reason that you're using DataGrid and not
> GridView? Are you still using VS.NET 2003...?
Mark Rae [MVP] - 05 Jul 2007 18:51 GMT
> Yes we do use vs.net 2003 . Company had already started developement
> before 2005 release. still they want to use the same one. I don't see they
> have any plan to update at the moment.
Hmm - OK... That's all well and good, but isn't really helping your career
very much...
2005 is already over 18 months old, 2008 isn't too far away now:
http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx
Presumably, your company intends to upgrade before mainstream support for
2003 ends:
http://support.microsoft.com/lifecycle/search/?sort=PN&alpha=Visual+Studio&Filte
r=FilterNO
It would be a shame to get left behind...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net