Dynamic DataGrid

C

CanoeGuy

I am wanting to dynamically display different columns in a DataGrid based on
what item the user chooses. As an example, if the user chooses Item A, I
want to display column1, column2, and column5. If the user chooses Item B, I
want to display column1, column2, column8 and column9. The columns that will
not be displayed to the user are always either Null or 0 (zero). I haven't
been able to find a working example or a solution anywhere in my research.

Thanks in advance for the help.
 
C

Curt

This is a BIG question , in that you can configure a DataGrid in so many
different ways! The right anwser depends on the way you are using the
DataGrid.

I almost always solve such questions in the core SQL itself, by writing the
SQL to match the columns required. Less coding is necessary to bind such
data to a DataGrid object this way, and just about any SQL you write will
work.

If you are creating the DataGrid in code, of if dynamic SQL is not an
option, then leverage static SQL by adding only the required columns to your
DataGrid. There are tons of examples of how to do this on the web. Here
are two starters:
http://odetocode.com/Articles/218.aspx
http://www.c-sharpcorner.com/Database/PlayingWithDataGridTA.asp

Good luck,
Curt
 
C

CanoeGuy

Hi Curt,

Thanks for your reply. Believe it or not it answers the big question that I
had of whether I should handle the data in the SQL or in the DataGrid. Can
you help me on the best way to filter out Null fields in the SQL Statement?
As long as I can get started, I can do the rest of the research.

Thanks,

//Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top