DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Wed, 22 Aug 2007 12:16:02 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    michael sorens am
          2    Ladislav Mrnka
                 3    michael sorens am
                        4    (Walter Wang [MSFT])


updating GridView cell background color   
I understand how to connect a SqlDataSource to a GridView and have a nice 
data-connected, paginated web page generated with virtually no coding. 
Starting from that base, I would like to add an extra column to the GridView 
and do two things: for each row, based on the value of another column, insert 
a string in the new column cell and set the background color of the new 
column cell. Suggested approaches would be appreciated.
Date:Wed, 22 Aug 2007 12:16:02 -0700   Author:  

RE: updating GridView cell background color   
Hi Michael,
you can create handler for RowDataBound event of your GridView. In this 
handler you will be able to access and modify cells and data of your current 
row.

protected void myGridView_OnRowDataBound(object sender, GridViewRowEventArgs 
e)
{
  if (e.Row.RowType = DataGridRowType.DataRow)
  {
    // e.Row.Cells contains collection of server side td elements, you can 
fill
   // text property or work with collection of controls inside this element
    e.Row.Cells[INDEX_OF_YOUR_COLUMN].Text = EvalMyField(e.Row.DataItem ); 
// DataItem contains source of data for this row, it is object used by data 
source to fill your row
    // you can also modify css style for your elelment
    e.Row.Cells[INDEX_OF_YOUR_COLUMN].Attributes.Add("style", ".......");
  }
} 

Regards,
Ladislav

"michael sorens" wrote:


> I understand how to connect a SqlDataSource to a GridView and have a nice 
> data-connected, paginated web page generated with virtually no coding. 
> Starting from that base, I would like to add an extra column to the GridView 
> and do two things: for each row, based on the value of another column, insert 
> a string in the new column cell and set the background color of the new 
> column cell. Suggested approaches would be appreciated.
Date:Wed, 22 Aug 2007 12:38:05 -0700   Author:  

RE: updating GridView cell background color   
Splendid! I had to test for DataControlRowType.DataRow rather than 
DataGridRowType.DataRow, but that essentially did most of what I needed.

Now how do I position the new column as the right-most column?
I first tried adding a new column of type Template in the visual designer. 
This new column became the first column. I tried the same thing 
programmatically by calling gridView.Columns.Add() in the PageLoad handler 
and it also became the first column. I then switched to Columns.Insert() but 
in the PageLoad handler the binding has not yet occurred, hence column count 
is still 0. When the binding occurs, the columns are added to the right, 
again leaving my new column as the left-most. What event handler would give 
me access to the GridView after the columns have been loaded so I can then 
add my new column where I want?
Date:Wed, 22 Aug 2007 13:28:09 -0700   Author:  

RE: updating GridView cell background color   
Hi Michael,

I'm glad that you've solved your first issue.

For the second question, have you tried to add the column in GridView's 
DataBound event? In this event, the data has been bound and those columns 
are generated, therefore you can add your column to the right-most.

Please let me know the result. Thanks.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Thu, 23 Aug 2007 05:16:17 GMT   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us