Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

check bound column in client side javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ganesh - 04 Jul 2007 22:45 GMT
Hi There,

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.

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.

How can i do this, your help much appreciated

Thanks
Mark Rae [MVP] - 04 Jul 2007 23:22 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
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.