Quote:
Originally Posted by Frinavale
What exactly are you trying to accomplish?
You may be having problems with inheriting the AutoGeneratedField class because the specifications (that you linked us to) says the following:
I have a feeling that you'll be interested in handling the GridView RowDataBound Event.
Frina: there is something wrong with the format of your post and I cannot quote it exactly as you posted it as you can see above.
Q: What exactly are you trying to accomplish?
I have a lookup table of Field names, Column captions, Column widths and DataFormatStrings. At RowCreated I lookup the fieldname and substitute my caption which could include <br>, set the width, and arrange for the correct format to be displayed. This actually worked decently except for a minor hack with the dataformatstring. The real problem occurred when I set AllowSorting to be true: Header.text no longer had the field names. I found the fieldnames at ((GridView)sender)._autoGenFieldProps but it was private, showed up only in the watch, and my entire lookup scheme that had worked perfectly, then failed. Not only was there nothing to lookup, but I discovered that if I stuck a caption at Header.Text, as I was wont to do, then the sort would not work as the linkbutton was not created.
Q: Specification says ..this class cannot be inherited..
Yea, not only that but it is a "sealed" class (FWIW)
Q: I have a feeling...
OK - It was a gut wrenching feeling, but I did get it all working thanks to an old bytes thread
here I did learn something, but it was a huge hack by the time I got thru.
My original post was to find out how to set up the inheritance so my override worked. Something like the following worked:
-
public class MyGridView : GridView
-
{
-
protected override AutoGeneratedField CreateAutoGeneratedColumn(AutoGeneratedFieldProperties fieldProperties)
-
{
-
AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
-
return field;
-
}
-
}
-
..
-
..
-
MyGridView GridView1 = new MyGridView()
-
In the above override I was able to lookup the field name and set the captions and still get the sort to work. Unfortuately, setting DataFormatString ended up as a true hack in every sense of the word and I had to use that reflection mechanism mentioned in an old thread in this forum.