Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2006, 11:16 PM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default Change a Datagrid cell background

Hello all
I'm trying to change a cell of a datagrid background when a condition becomes true.let me explain more:
I have a datagrid with different columns.one of these columns is a string that contains "0"s and "1"s.i want to check this cell.for example if the first character was "1" then the first cell should have a different background column and so on.
I wrote my codes like this:
1-a datagrid that has OnDataBinding(it calls a sub)
2-my sub is like this:
sub Changebg(s As Object,e As System.EventArgs)
for each myItem As DataGridItem in DataGrid1.Items
if first char="1" then
change the first cell background
if second char="1" then
change the second cell background
and so on ......
but it doesn't change any cell background
and this is the code for accessing the string field:
c=myItems.cells(12).text
and for changin the background i used:
myItem.cells(1).BackColor=skyblue
would you please help me.I'm not familiar with .net and i think i didn't use these codes correctly
i would be very happ if some one help me
thank you


 
Old September 28th, 2006, 01:53 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default

this is the code that i've written for changing bg color of a cell of dartagrid.would please tell me is it correct?
sub Changebg(s As Object,e As System.EventArgs)
    Dim c
    for each myItem As DataGridItem in DataGrid1.Items
        c=myItem.Cells(22).text
                    If Left(c, 1) = "1" Then
                        myItem.Cells(12).BackColor = Red
                    End If
        dim c1
        c1=left(c,2)
                    If Right(c1, 1) = 1 Then
                        myItem.Cells(11).BackColor = Red
                    End If
        Dim c2
        c2=left(c,3)
                    If Right(c2, 1) = 1 Then
                        myItem.Cells(10).BackColor = Red
                    End If
        Dim c3
        c3=left(c,4)
                    If Right(c3, 1) = 1 Then
                        myItem.Cells(15).BackColor = Red
                    End If
        Dim c4
        c4=left(c,5)
                    If Right(c4, 1) = 1 Then
                        myItem.Cells("16").BackColor = Red
                    End If
        Dim c5
        c5=left(c,6)
                    If Right(c5, 1) = 1 Then
                        myItem.Cells("18").BackColor = Red
                    End If
        Dim c6
        c6=left(c,7)
                    If Right(c6, 1) = 1 Then
                        myItem.Cells("19").BackColor = Red
                    End If
                    If Right(c, 1) = 1 Then
                        myItem.Cells("21").BackColor = Red
                    End If
    next
End Sub
and i set OnDataBinding="changebg" for my datagrid properties
It's near a month that i'm searching for the solution but i couldn't find anything usefull
thank you

 
Old October 7th, 2006, 06:48 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 201
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to hastikeyvan
Default

I found the problem.i should use OnItemDataBound for calling changebg
and changebg should be:
    Protected Sub changebg(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)





Similar Threads
Thread Thread Starter Forum Replies Last Post
change color of background meena88 C# 2005 3 December 1st, 2009 04:48 AM
Setting background image for gridvew cell anup_daware .NET Framework 2.0 0 September 17th, 2007 05:18 AM
Change a Datagrid cell background hastikeyvan ASP.NET 2.0 Basics 2 September 12th, 2006 11:23 PM
change background color of cell based on value vurtman ASP.NET 1.0 and 1.1 Basics 4 February 26th, 2004 03:52 PM
change background Frank1111 ASP.NET 1.0 and 1.1 Basics 5 October 16th, 2003 06:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.