Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Dynamically Setting Up a Gridview Based on Data Content

Reply
Thread Tools

Dynamically Setting Up a Gridview Based on Data Content

 
 
Brett
Guest
Posts: n/a
 
      01-04-2008
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

 
Reply With Quote
 
 
 
 
Toze
Guest
Posts: n/a
 
      01-06-2008
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


"Brett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      01-08-2008
On 4 Jan, 16:24, Brett <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
Brett
Guest
Posts: n/a
 
      01-08-2008
I appreciate the help. I got it. Thanks again.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: Only Content controls are allowed directly in a content page that contains Content controls. hazz ASP .Net 6 06-09-2010 01:54 PM
dynamically creating a GridView with x rows based on database table column design Andy B ASP .Net 0 08-03-2008 11:29 AM
Setting BackColor of GridView cell dynamically Mike P ASP .Net 1 08-30-2006 03:07 PM
Setting GridView SelectedIndex based on a row value Jay Pondy ASP .Net 1 03-03-2006 03:31 AM
Dynamic gridview content based on user role? Troy Dot Net ASP .Net Security 2 01-23-2006 01:07 PM



Advertisments