|
-
Feb 16th, 2008, 02:46 AM
#1
Thread Starter
Member
Changing checkbox color in gridview
Hi everyone,
I have a ASP.Net gridview that is bound to a datasource. One of the fields in the datasource is a SQL bit value called Online which is linked to the gridview as a readonly checkbox.
I am hoping to change the color of the checkbox depending on the Online value.
Ie: Online = 1/true - Color checkbox green
Online = 0/false - Color checkbox red
Could someone guide me in the right direction with this?
I am guessing I would have to do this around the datasource selected event?
Thanks in advance.
-
Feb 18th, 2008, 02:44 AM
#2
Re: Changing checkbox color in gridview
Hello,
Create a handler for the RowDataBound event of the GridView.
Inside that handler, find the checkbox and depending if it's checked or not, add either the CSS attribute to the control, or force the color change with the control's properties.
The code should be something like this:
Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
'Replace "CheckboxName" for the generic name of your checkbox
Dim ChkBox as CheckBox = CType(e.Row.FindControl("CheckboxName"), CheckBox)
If ChkBox.Checked = True Then
ChkBox.CssClass = "chkbox1"
Else
ChkBox.CssClass = "chkbox2"
End If
End If
End Sub
I have not tested if the change of color works properly, but it looks about right.
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Feb 27th, 2008, 01:48 AM
#3
Thread Starter
Member
Re: Changing checkbox color in gridview
Thank you very much for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|