And others can get or set them property. So that's itemStyle why fail to compile.
If you need to make it a bit shorter, you can set the ItemStyle property separately outside.
Best regards,
Sam
IIS.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
None
0 Points
26 Posts
Initialisation of ButtonField
Sep 25, 2019 10:59 AM|Andrey Belyakov|LINK
Hello folks,
Initialisation of ButtonField
I have a code which perfectly working:
ButtonField ORDER_NO = new ButtonField();
ORDER_NO.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
ORDER_NO.ButtonType = ButtonType.Link;
ORDER_NO.Visible = true;
A need to make it a bit shorter:
ButtonField ORDER_NO = new ButtonField() {
ItemStyle.HorizontalAlign = HorizontalAlign.Center,
ButtonType = ButtonType.Link,
Visible = true;
};
this code are failed on compilation of
ItemStyle.HorizontalAlign = HorizontalAlign.Center,
with Error CS0747 Invalid initializer member declarator
Did anybody have an idea what is wrong and how to get it compilable?
Control already inherited and in constructor initialisation are done.
But I still like to known why direct approach didn't work.
Contributor
3370 Points
1409 Posts
Re: Initialisation of ButtonField
Sep 26, 2019 05:47 AM|samwu|LINK
Hi Andrey Belyakov,
ItemStyle Property only get the style of any text-based content displayed by a data control field, but cannot set style.
This is ItemStyle property doc: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.datacontrolfield.itemstyle?view=netframework-4.8
And others can get or set them property. So that's itemStyle why fail to compile.
If you need to make it a bit shorter, you can set the ItemStyle property separately outside.
Best regards,
Sam
None
0 Points
26 Posts
Re: Initialisation of ButtonField
Oct 02, 2019 08:05 AM|Andrey Belyakov|LINK
ItemStyle Property only get the style of any text-based content displayed by a data control field, but cannot set style.
------
Good explanation.
But, sorry, not a proper one.
In the provided code not used a property setter. Accessed only getter, which supposed to be available... after instance initialized.
However, this is not a regular code, this is an instance initialization and property, I assume, not ready for use.
So, to solve the problem, require to define property itself (not a value) and for defined property set required values.
Solution is: