check bound column in client side javascript

Discussion in 'ASP .Net' started by Ganesh, Jul 4, 2007.

  1. Ganesh

    Ganesh Guest

    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
    Ganesh, Jul 4, 2007
    #1
    1. Advertising

  2. "Ganesh" <> wrote in message
    news:O$...

    > 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?sour..._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 checkbox 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.rowdatabound.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,


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 4, 2007
    #2
    1. Advertising

  3. Ganesh

    Ganesh Guest

    On Jul 4, 11:22 pm, "Mark Rae [MVP]" <> wrote:
    > "Ganesh" <> wrote in message
    >
    > news:O$...
    >
    > > 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,
    >
    > --
    > Mark Rae
    > ASP.NET MVPhttp://www.markrae.net




    Hi Mark,

    Thanks a lot, that was really useful. I'll try this now.
    Ganesh, Jul 5, 2007
    #3
  4. "Ganesh" <> wrote in message
    news:...

    > 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
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 5, 2007
    #4
  5. Ganesh

    Ganesh Guest

    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


    "Mark Rae [MVP]" <> wrote in message
    news:%...
    > "Ganesh" <> wrote in message
    > news:...
    >
    >> 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
    > ASP.NET MVP
    > http://www.markrae.net
    Ganesh, Jul 5, 2007
    #5
  6. "Ganesh" <> wrote in message
    news:...

    > 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&Filter=FilterNO

    It would be a shame to get left behind...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 5, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John E.
    Replies:
    3
    Views:
    4,458
    masoud bayan
    Mar 25, 2005
  2. Boss302
    Replies:
    0
    Views:
    1,033
    Boss302
    Nov 21, 2006
  3. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    218
    Ravichandran Mahalingam
    Jan 9, 2004
  4. John E.

    Move bound column to right of dynamic column in datagrid?

    John E., Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    230
    Elton Wang
    Mar 28, 2005
  5. TS
    Replies:
    3
    Views:
    405
    Walter Wang [MSFT]
    Aug 16, 2007
Loading...

Share This Page