Last post Jul 09, 2008 07:08 AM by wullie
Jul 06, 2008 06:46 AM|wullie|LINK
When using a grdivew you can specify properties such as border, font colour etc in the declarative syntax of the template. For example...
<asp:GridView ID="grdExample" runat="server">
It also allows you to specify the style in the declatative syntax of of the gridview. For example...
<asp:GridView ID="grdExample" SelectedRowStyle-BackColor="Green" runat="server">
Can anyone tell me how I can make my custom control templates expose the properties like this?
Jul 06, 2008 12:56 PM|vgiambattista|LINK
This is a very fun topic. Here are some links to help you hit the ground running:
Jul 06, 2008 02:37 PM|ihsany|LINK
SelectedRowStyle-BackColor is a public attribute in GridView class. You can add some public attributes to your custom class like this;
public Color SelectedRowStyle-BackColor
ViewState["SelectedRowStyle-BackColor"] = value;
i hope this help you
Jul 07, 2008 05:28 AM|wullie|LINK
Ihsany, from what I see that cannot be correct. One, that name has a - characater in it, which is illegal in member names. Two, reflector confirms this by showing that Gridview does not have a member with that name.
James, thanks for the links but I still cannot seem to expose the properties of the templates in the declarative syntax.
For example, in the microsoft MSDN example.
I would expect to be able to delcare my control like so
<PREFIX:MyControl ID="MyControl" ItemTemplate-Message="My Message" runat="server">
<PREFIX:MyControl ID="MyControl" runat="server">
<ItemTemplate Message="My Message">Tempalte Layout</ItemTemplate>
Jul 07, 2008 07:37 AM|Peter Bucher|LINK
Have a look at the "PersistenceMode"-Enumeration:
Jul 09, 2008 07:08 AM|wullie|LINK
I worked out what I had to do. I need to implement the attribute <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _ on any properties that expose an object so that the delarative syntax exposes the contents of the object, rather
than for the object itself.
A combination of this and the PersistenceMode attribute mentioned by Peter above extend it to allow properties to defined just like a template property. The code ended up looking like so.
Public ReadOnly Property ItemStyle() As Style
If _editRowStyle Is Nothing Then
_editRowStyle = New Style
You can find out more about the attribute with the link below.