0

I'm trying to create an extended gridview class that will enable me to always have a footerrow that can be used to add data. That's the end goal.

I've tried classes that were found elsewhere on stackoverflow, but the code I found is apparently buggy (it either works when the footerrow is the only row, or it works when the footerrow is not the only row, but never both. Possibly related to the fact that I have dropdownlists in my rows). This problem was explained here: Bizarre issue with customized gridview control

The class itself is also problematic, in that the formatting is kind of messed up when the footerrow is the only row. It just doesn't look right... the color formatting is gone.

So now I'm thinking what I really want to do, is rewrite the data sources so they're based on UNION queries, so that there's always one blank row with -1 in the key column (my tables always have single incremental primary keys, so no legit row will ever have -1 in the key column), and then have a class that automatically hides any row where the value in the "DataKeyNames" field is -1.

Problem: I have no idea how to do this. :) I know how to do it in the aspx.cs code (RowDataBound event -- if(condition) {e.Row.Visible = false;}), and I know how to do it via CSS, but I don't know how to do it automatically in an extended class. I'm afraid I'm a little lost when it comes to writing extended classes.

To sum up, what I'd like to do is put an extended gridview class in my aspx code, set the usual gridview things, and have the only additional thing in my code be an added "UNION SELECT" in my datasource, and have it just automatically hide the row that the UNION SELECT provided, so that there's always at least one row in the gridview (thereby taking care of the entire footerrow not showing up problem), without me having to code anything extra in a RowDataBound event every time, because I have these gridview controls EVERYWHERE in my code.

Many thanks for any help you can provide! :)

Katerine459
  • 465
  • 1
  • 3
  • 13
  • This is too broad. Whatever you are asking is kind of adding new behavior to existing gridview control. You can do this by inheriting grid view control and overriding it's behavior such as rendering and data binding. You can also explore the solutions you already found and try to get them fixed. – Chetan Mar 28 '18 at 00:31
  • Thank you, but that would be my problem. I've been trying to get the solutions I found fixed for almost two weeks now, and I never particularly liked those solutions to begin with. As for inheriting the grid view control and overriding its behavior... I know that's what's needed. The problem is that I seem to have a bit of a mental block when it comes to overriding classes, and there are about 150 methods and events in the gridview class, and I don't even know where to start. I was hoping somebody could kind of give me a basic coding starting point. Thanks. – Katerine459 Mar 28 '18 at 00:36
  • Regarding: "too broad." The behavior I want is as follows: I want to make a class that inherits gridview, declare instances of that class in my pages, always declaring a value for "DataKeyNames" when setting up the instance, and have the class automatically hide (make invisible) any row where the value in the "DataKeyNames" field = -1, so that the row technically exists, but is not displayed (thereby getting around the issue of gridview footerrows only showing up when there's at least one existing row). – Katerine459 Mar 28 '18 at 00:40

0 Answers0