473,471 Members | 4,616 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Rant: asp:DataGrid feels like object oriented straightjacket forrow-level operations

Suppose you want to do either of these:

A) Set display properties (e.g. color or boldness of text) of a cell based on a value
of another cell in the same row.

B) Set the display properties of a whole row based on values of one or more cells in
that row.

Well, these seem like reasonable things to want to do. If one was writing one's own
code to spit out HTML table tr and td tags like in days of old (like, say, 6 years
ago back in the paleolithic era) one could do that pretty easily. One would have the
dataset for the entire row. One would have a for loop for going thru the dataset. One
could put tests in place to check values in the dataset current row to use to set
flags to then set properties in various td cells in the row as one writes out the
HTML to generate the table.

Of course, writing code by hand to generate an HTML table from scratch is tedious and
time-consuming. So we use web dev frameworks that hopefully lighten the programming
burden. But ASP.Net seems to do so at the expense of putting one in a straightjacket.

See below. One can inherit from DataGridTextBoxColumn to override the writing of each
cell in a table column. But the object oriented context created by this approach
robs one of access to the data for the rest of the row.

Also, one has to inherit a class from DataGridTextBoxColumn for each column where one
wants to play formatting games. So if one wants to set display properties on a dozen
columns one has to write a dozen classes that inherit from DataGridTextBoxColumn.
This seems like a pain to me.

http://www.syncfusion.com/FAQ/Window...44c.aspx#q745q
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush
foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or backbrush
// depending upon some crireria on the cell value
// Here, we color anything that begins with a letter higher than 'F'
try{
object o = this.GetColumnValueAtRow(source, rowNum);
if( o!= null)
{
char c = ((string)o)[0];
if( c > 'F')
{
// could be as simple as
// backBrush = new SolidBrush(Color.Pink);
// or something fancier...
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 200, 200),
Color.FromArgb(128, 20, 20),
LinearGradientMode.BackwardDiagonal);
foreBrush = new SolidBrush(Color.White);
}
}
}
catch(Exception ex){ /* empty catch */ }
finally{
// make sure the base class gets called to do the drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush, foreBrush,
alignToRight);
}
}
}
Jan 17 '06 #1
2 1081
Dan
On binding or after binding loop through your cells and update their
formatting based on other cell values.

Datagrids can do this, i have done this, go learn about datagrids before you
put down the best component in .net
--
Dan
"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit .com>
wrote in message news:%2***************@TK2MSFTNGP10.phx.gbl...
Suppose you want to do either of these:

A) Set display properties (e.g. color or boldness of text) of a cell based
on a value of another cell in the same row.

B) Set the display properties of a whole row based on values of one or
more cells in that row.

Well, these seem like reasonable things to want to do. If one was writing
one's own code to spit out HTML table tr and td tags like in days of old
(like, say, 6 years ago back in the paleolithic era) one could do that
pretty easily. One would have the dataset for the entire row. One would
have a for loop for going thru the dataset. One could put tests in place
to check values in the dataset current row to use to set flags to then set
properties in various td cells in the row as one writes out the HTML to
generate the table.

Of course, writing code by hand to generate an HTML table from scratch is
tedious and time-consuming. So we use web dev frameworks that hopefully
lighten the programming burden. But ASP.Net seems to do so at the expense
of putting one in a straightjacket.

See below. One can inherit from DataGridTextBoxColumn to override the
writing of each cell in a table column. But the object oriented context
created by this approach robs one of access to the data for the rest of
the row.

Also, one has to inherit a class from DataGridTextBoxColumn for each
column where one wants to play formatting games. So if one wants to set
display properties on a dozen columns one has to write a dozen classes
that inherit from DataGridTextBoxColumn. This seems like a pain to me.

http://www.syncfusion.com/FAQ/Window...44c.aspx#q745q
public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds,
System.Windows.Forms.CurrencyManager
source, int rowNum, System.Drawing.Brush backBrush,
System.Drawing.Brush
foreBrush, bool alignToRight)
{
// the idea is to conditionally set the foreBrush and/or
backbrush
// depending upon some crireria on the cell value
// Here, we color anything that begins with a letter higher than
'F'
try{
object o = this.GetColumnValueAtRow(source, rowNum);
if( o!= null)
{
char c = ((string)o)[0];
if( c > 'F')
{
// could be as simple as
// backBrush = new SolidBrush(Color.Pink);
// or something fancier...
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 200, 200),
Color.FromArgb(128, 20, 20),
LinearGradientMode.BackwardDiagonal);
foreBrush = new SolidBrush(Color.White);
}
}
}
catch(Exception ex){ /* empty catch */ }
finally{
// make sure the base class gets called to do the
drawing with
// the possibly changed brushes
base.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, alignToRight);
}
}
}

Jan 17 '06 #2
Dan,

You do not tell me how to do it. I've read the class members of
System.Web.UI.WebControls.DataGrid and do not see an obvious property or method for
getting to individual rows after a DataBind to, say, set CssClass for each row or
something else for each row.

So how can this be done?

Dan wrote:
On binding or after binding loop through your cells and update their
formatting based on other cell values.

Datagrids can do this, i have done this, go learn about datagrids before you
put down the best component in .net

Jan 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim Smith | last post by:
In my .cs code I populate set the DataSource appropriately and I can get my DataGrid to appear, though sorting throws an error 'dgDataGrid1__ctl1__ctl0' of type 'DataGridLinkButton' must be placed...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. I do not just want to print the current page, I...
1
by: Michael M | last post by:
Hi I am trying to add mouseover property to asp:datagrid in the asp .net page My pag So the output in HTML for a row should look like <tr style="onmouseover=this.bgcolor=#ff0000;...
6
by: RSB | last post by:
Hi Everyone, i am using a ASP: DataGrid control in the page and for each row i have a Delete Button Column. Every thing works fine. But now i want to add a Java script confirmation check for the...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
2
by: John | last post by:
Hi, First off .. I am very new to ASP.NET (.NET in general), so this may be a very basic question. I have traditionally used a set of style classes for html tables and the first row in those...
15
by: John Blair | last post by:
Hi, Code attached but the line that gives me an error is MyDataGrid.Columns(2).Visible = False It actually gives me an error for any value instead of 2 even when 9 bound columns of data exist....
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
2
by: =?Utf-8?B?RXNlbWk=?= | last post by:
I have a datatable that contains a number of web addresses as type nvarchar (eg 'www.msdn.com'). I want to use these as hyperlinks in a datagrid column. Whats the best way to do this? How can I...
2
by: getziiiiiiiiiii | last post by:
Hi There. . I need some help in paging (which is not working) in ASP:DATAGRID My Data source id is a function which returns DataTable to this datagrid. Do i need a code behind to get the next...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.