Results 1 to 9 of 9

Thread: checkbox datagrid

  1. #1

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    checkbox datagrid

    i have a checkbox column in my datagrid

    id = chkSelected

    now i want if that is true then the colour is "green"

    it maybe simple enough but im having a nightmare with it

    any help or links would be much appreciated

    NB i shall make this row then invisible as i wish to check the row under certain conditions, i dont think this shall effect my above problem though
    i just really want to say if its checked then its this colour
    it works 60% of the time, all the time.

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: checkbox datagrid

    override the databind even for the datagrid.

    For each row, find that control and verify the "checked" property.

    If it is checked, either modify the appropriate cell's background color in the row, or apply a style to the row itself that colors the backgrounds.

    Changing the background should be akin to (from my head, here, not checked in VS)

    e.Item.Cells[0].Style.BackgroundColor = "#AAFFAA"; //AAFFAA is one shade of green
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: checkbox datagrid

    Why not #00FF00? That's discrimination based upon color.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: checkbox datagrid

    =D

    Cause it is TOO green, ick!
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  5. #5
    Junior Member
    Join Date
    Oct 2005
    Posts
    16

    Re: checkbox datagrid

    Is this an updatable datagrid or just used for displaying the data without any need of editing the data.

    Becoz if its an updatable one you have check if the checkbox is checked while binding the data as Lord said by writing in the databind event and if the user explicitly checks it then u can as well check in checkboxchanged event.

  6. #6

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: checkbox datagrid

    data wont be edited in it

    i have some kind of clours workin on it now but it definitely isnt working right,
    the checkbox is not databound so is there a way of making the checkbox stay checked on that row even after refreshes, i shall i need a bound column to determine row colours,, thanks
    it works 60% of the time, all the time.

  7. #7

    Thread Starter
    Fanatic Member d2005's Avatar
    Join Date
    Aug 2005
    Location
    ireland
    Posts
    620

    Re: checkbox datagrid

    i need the row to be checked when select is pressed, this then needs to leave the row checked for good,

    perheps i need to look at this differently
    it works 60% of the time, all the time.

  8. #8
    Fanatic Member
    Join Date
    Jun 2005
    Posts
    625

    Re: checkbox datagrid

    Lord Rat's setting the color command should work. You probably want to do it in the DataGrid1_ItemDataBound(..) event.

  9. #9
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: checkbox datagrid

    As for the checkbox being checked, you need to store in a persistent variable the checked/unchecked values of all the checkboxes and refresh that on every item databound. Persisting arrays can be accomplished using either the Session object or the ViewState object.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width