Dynamically Setting Up a Gridview Based on Data Content

B

Brett

I am new at this type of task, so a quick template or even article reference
would be helpful.

I have an ObjectDataSource derived from and XSD type data set, with Get and
Fill methods, to populate a gridview. I want to pull the data and scan it to
set up the grdiview. For example:

.. The data has columns for stats such as UseStat1, Stat1value and Stat1Title.
.. If UseStat1 is true, add a grid column bound to Stat1Value AND
.. Set the new grid column's header text to the contents of Stat1Title

How do I collect the data from the ObjectDataSource, so I can scan it? Do I
load it into a dataset or data table, etc. and how? I can't find anything
that explains this.

Let me know if you can assist or need clarification.

Thanks
 
T

Toze

maybe the best way is to use the rowDatabound GridView Event
cast the e.Row.DataItem to your object ITEM

get the row objects(e.Row.FindControl) and change properties
Example
((TextBox) e.Row.FindControl("TextBox1").Visible=False);
and change properties
 
P

Phil H

I am new at this type of task, so a quick template or even article reference
would be helpful.

I have an ObjectDataSource derived from and XSD type data set, with Get and
Fill methods, to populate a gridview.  I want to pull the data and scan it to
set up the grdiview.  For example:

. The data has columns for stats such as UseStat1, Stat1value and Stat1Title.
. If UseStat1 is true, add a grid column bound to Stat1Value AND
. Set the new grid column's header text to the contents of Stat1Title

How do I collect the data from the ObjectDataSource, so I can scan it?  Do I
load it into a dataset or data table, etc. and how?  I can't find anything
that explains this.

Let me know if you can assist or need clarification.

Thanks

Hi

Since you have set up a DataSet, and you require programmatic control
of the GridView, there is no real need for an ObjectDataSource. Just
bind the GridView directly to the DataTable using the DataSource
property (not DataSourceID) in code. Set AutoColumnsGeneration to
false and create the columns according to your own rules. The
HeaderText is available as a property of each column.

The trouble with using ObjectDataSource in this case is that the
DataBindings have to be defined as design time and the underlying data
is effectively hidden from you at run time. Its purpose is to simplify
the normal databinding and appearance of the columns so that you don't
have to write much code. But if you require programmatic access to
these things it's best to consider the alternatives where you have
complete control.
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top