DataGrid control is only half baked, is that going to change in ASP.NET 2.0?

N

~~~ .NET Ed ~~~

Well, maybe not half-baked but 75%. I find very frustrating working with the
DataGrid control. It offers a lot of functionality which really comes in
handy. Unfortunately you can only enjoy a DataGrid to its fullest when you
"drop" it on a web form. There you can modify all sorts of properties for
the look and behaviour to your hearts content.

But then, when you decide to use the DataGrid as a child control of a web
custom composite control, you suddenly find yourself working with one arm
only. Lots of the features and properties are only available read-only (GET)
when you want to create and adjust the instance programmatically.

For example, all the style information for header/footer/item/alternating
item etc. are GET properties for a reason that still escapes my reasoning.
The only way to get a limited access to SOME of those are by using the
ItemBound or ItemCreated event. The great disadvantage of that approach is
that it is then applied to each item rather than just once during
initialization.

Has there been any noticeable change in DG 2.0? I had 2.0 on my laptop but
it screwed up the whole Windows installation so I had to reformat the disk.
 
B

Brock Allen

But then, when you decide to use the DataGrid as a child control of a
web custom composite control, you suddenly find yourself working with
one arm only. Lots of the features and properties are only available
read-only (GET) when you want to create and adjust the instance
programmatically.

For example, all the style information for
header/footer/item/alternating item etc. are GET properties for a
reason that still escapes my reasoning. The only way to get a limited
access to SOME of those are by using the ItemBound or ItemCreated
event. The great disadvantage of that approach is that it is then
applied to each item rather than just once during initialization.

Well working with any control inside a CompositeControl is always done programmatically.
But I don't understand what you mean that you can't set style properties?
Perhaps the HeaderStyle property itself is readonly, but you're getting back
a reference upon which you can set the properties:

DataGrid g = new DataGrid();
g.HeaderStyle.BackColor = Color.Red;

Or are there other aspects that you're having trouble with?
Has there been any noticeable change in DG 2.0? I had 2.0 on my laptop
but it screwed up the whole Windows installation so I had to reformat
the disk.

Yes and No. The DataGrid is such a beast (30K+ LOC) that they started from
scratch and created a GridView control. It has all the same functionality
(Pageing, Sorting, Templates, etc) but it fits into the declarative data
binding model. This is what makes Data Binding (and thus the GridView) novel
in 2.0. This does make using the GridView a bit easier for things such as
Paging and Sorting as it can automatically do those things for you, whereas
with the DataGrid you had to write all of that code manually.
 
S

Scott Allen

There is a new control, the GridView, that will contain more
'features' than a DataGrid, but I'm not sure if it solves your
specific point of pain.

If you wanted to assign a TableItemStyle to one of the style
properties, you'd have to construct the style object by setting all
the individual properties you need - I don't think there would be any
sort of savings.
 
A

AlanM

RE: "all the style information for header/footer/item/alternating
item etc. are GET properties"

Yes, but that doesn't mean you can't change style properties for a
datagrid in a composite control.
The sample below worked for me. Well, the colors don't, but that's a
different problem.

namespace WebControlLibrary2
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>"),
Designer(typeof(WebControlLibrary2.Design.WebCustomControl1Designer))]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
{

public override ControlCollection Controls
{
get
{
EnsureChildControls();
return base.Controls;
}
}

public DataGrid _datagrid;
protected override void CreateChildControls()
{
_datagrid = new DataGrid();

TableItemStyle myNewItemStyle = new TableItemStyle();
myNewItemStyle.BackColor = Color.Blue;
_datagrid.ItemStyle.CopyFrom(myNewItemStyle);

TableItemStyle myNewAltItemStyle = new TableItemStyle();
myNewAltItemStyle.BackColor = Color.SkyBlue;
_datagrid.AlternatingItemStyle.CopyFrom(myNewAltItemStyle);

Controls.Add(_datagrid);

}

}

}

namespace WebControlLibrary2.Design
{
public class WebCustomControl1Designer : ControlDesigner
{

public override string GetDesignTimeHtml()
{
ControlCollection cc = ((WebCustomControl1)Component).Controls;
((WebCustomControl1)Component)._datagrid.DataSource =
DesignTimeData.GetDesignTimeDataSource(DesignTimeData.CreateDummyDataTable(),
5);
((WebCustomControl1)Component)._datagrid.DataBind();
return base.GetDesignTimeHtml ();
}

}
}

->A
 
N

Nick Stansbury

Alternatively you could look at some of the datagrid replacements on the
market - Telerik (www.telerik.com) have a good one in beta at the
moment -scheduled for release in about a fortnight.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top