473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

want override, but stuck on the inheritance

BeemerBiker
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 AutoGeneratedField is not part of my class ..

public partial class printit : System.Web.UI.Page


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)
Expand|Select|Wrap|Line Numbers
  1.    public partial class printit : System.Web.UI.Page, System.Web.UI.WebControls.DetailsView
  2. {
  3.  
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.AutoGenerateColumns=True and coded up the following, but the override is never called.

Expand|Select|Wrap|Line Numbers
  1.  public class MyDetailsView : DetailsView
  2.     {
  3.         public MyDetailsView()
  4.         {
  5.         }
  6.         protected override AutoGeneratedField CreateAutoGeneratedRow(AutoGeneratedFieldProperties fieldProperties)
  7.         {
  8.             AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
  9.             return field;
  10.         }
  11.  
  12.     }
  13.  
  14.     public partial class printit : System.Web.UI.Page
  15.     {
  16. ...rest of my program...
  17.  

===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.
Mar 18 '09 #1
3 2342
Frinavale
9,735 Expert Mod 8TB
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:
AutoGeneratedField 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.
Mar 18 '09 #2
tlhintoq
3,525 Expert 2GB
If you are going to Override it in the child class, you must mark it Virtual in the Parent
Mar 18 '09 #3
@Frinavale
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:

Expand|Select|Wrap|Line Numbers
  1. public class MyGridView : GridView
  2. {
  3.     protected override AutoGeneratedField  CreateAutoGeneratedColumn(AutoGeneratedFieldProperties fieldProperties)
  4.     {
  5.         AutoGeneratedField field = new AutoGeneratedField(fieldProperties.DataField);
  6.          return field;
  7.     }
  8. }
  9. ..
  10. ..
  11. MyGridView GridView1 = new MyGridView()
  12.  
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.
Mar 19 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: | last post by:
Sorry, I mixed up the code- reposting with correct example now :) I'm trying to better understand the use of inheritance vs. the implementation of a handler. I wanted to ask this question to the...
3
by: news.microsoft.com | last post by:
Hi, It is possible to override a non virtual method with the "new" keyword So how is this different from specifying a method as virtual then providing the override keyword? Is there any...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
8
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
1
by: naveen | last post by:
Hi why there are 2 diffrenet types in heritence of defining methods 1. one redefining method of base class using new keyword 2.customizing method using virtual and override keywords is any one...
21
by: bonk | last post by:
Did anyone EVER come across the need to use "new" in a method declaration (breaking with inheritance / versioning)? Allthough I know what it does and how it is used I really have a hard time to...
5
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This...
2
by: mjansen.merge.emed | last post by:
Is there a way to override inline within the <bodya style of an element but not do it with a style attribute on the element? I know CSS Inheritance works for some styles, but doesn't appear to...
8
by: puzzlecracker | last post by:
The statement is taken from FAQ . What about non-virtual functions? Can they be overriden? I still don't see a good justification to prefer private inheritance over composition. In fact, I have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.