want override, but stuck on the inheritance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BeemerBiker
    New Member
    • Jul 2008
    • 87

    want override, but stuck on the inheritance

    I want to use the C# example shown here

    Ok, I have done simple overrides before so I coded up

    protected override Auto...

    well, I didnt even get that far as intellisense made it clear that AutoGeneratedFi eld is not part of my class ..

    public partial class printit : System.Web.UI.P age


    So I tried adding "DetailView " to the class so I could inherit it (this was just a wild guess that once worked in c++ for me)
    Code:
       public partial class printit : System.Web.UI.Page, System.Web.UI.WebControls.DetailsView
    {
    Anyway, the above does not work giving me a cannot have multiple base classes.

    There is a really good example of what I want to do here but the author leaves the description on how to "use it" for a later date.

    Question: What do I put in to my C# page that willl cause the override to be fired? I assume I have to inherit the class that does the firing and I do not know enough about inheritance to do this.

    I have set GridView1.AutoG enerateColumns= True and coded up the following, but the override is never called.

    Code:
     public class MyDetailsView : DetailsView
        {
            public MyDetailsView()
            {
            }
            protected override AutoGeneratedField CreateAutoGeneratedRow(AutoGeneratedFieldProperties fieldProperties)
            {
                AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
                return field;
            }
    
        }
    
        public partial class printit : System.Web.UI.Page
        {
    ...rest of my program...

    ===wait wait wait===

    ok, just realized I should have used MyGridView instead of the above "MyClass" and then used MyGridView when createing GridView1 . That gets me a bunch of new overrides though not the one I am looking for. However, I am in the right direction.
    Last edited by BeemerBiker; Mar 18 '09, 07:21 PM. Reason: learned something since I posted this
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What exactly are you trying to accomplish?

    You may be having problems with inheriting the AutoGeneratedFi eld class because the specifications (that you linked us to) says the following:
    Originally posted by article
    AutoGeneratedFi eld Class

    Represents an automatically generated field in a data-bound control. This class cannot be inherited.
    I have a feeling that you'll be interested in handling the GridView RowDataBound Event.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      If you are going to Override it in the child class, you must mark it Virtual in the Parent

      Comment

      • BeemerBiker
        New Member
        • Jul 2008
        • 87

        #4
        Originally posted by Frinavale
        What exactly are you trying to accomplish?

        You may be having problems with inheriting the AutoGeneratedFi eld 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 DataFormatStrin gs. 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 dataformatstrin g. 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)send er)._autoGenFie ldProps 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:

        Code:
        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 DataFormatStrin g 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.

        Comment

        Working...