Dynamically Setting Up a Gridview Based on Data Content

Discussion in 'ASP .Net Web Controls' started by Brett, Jan 4, 2008.

  1. Brett

    Brett Guest

    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
     
    Brett, Jan 4, 2008
    #1
    1. Advertising

  2. Brett

    Toze Guest

    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" <> wrote in message
    news:...
    >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
    >
     
    Toze, Jan 6, 2008
    #2
    1. Advertising

  3. Brett

    Phil H Guest

    On 4 Jan, 16:24, Brett <> 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.
     
    Phil H, Jan 8, 2008
    #3
  4. Brett

    Brett Guest

    I appreciate the help. I got it. Thanks again.
     
    Brett, Jan 8, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jay Pondy
    Replies:
    1
    Views:
    6,935
    Christopher Reed
    Mar 3, 2006
  2. hazz
    Replies:
    6
    Views:
    50,066
    SkyUCHC
    Jun 9, 2010
  3. Mike P
    Replies:
    1
    Views:
    3,981
    harlequinben
    Aug 30, 2006
  4. Andy B
    Replies:
    0
    Views:
    500
    Andy B
    Aug 3, 2008
  5. Troy Dot Net

    Dynamic gridview content based on user role?

    Troy Dot Net, Jan 9, 2006, in forum: ASP .Net Security
    Replies:
    2
    Views:
    217
    Troy Dot Net
    Jan 23, 2006
Loading...

Share This Page