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=UT...
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=Ja...
To do this, you need to use the DataGrid's RowDataBound event:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gr...
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,