Declaring the name of a grid

Discussion in 'ASP .Net Datagrid Control' started by eagle, Sep 6, 2005.

  1. eagle

    eagle Guest

    How can I declare the name of a grid, then use it to bind it to the
    datasource?

    I have 3 grids, each with different id's. dgOne, dgTwo, dgThree. I want to
    be able to do things to each grid. So I need to pass the name of the grid
    to the GetData procedure. What I have done so far:

    arrGridNames(1) = "One"
    arrGridNames(2) = "Two"
    arrGridNames(3) = "Three"

    dg = "dg" & arrGridNames(1)

    so that I come up with dgOne. But of course that is a string, and can't be
    a datagrid, so when I try to bind it, I get the error: public member
    'Datasource" on type 'String' not found.

    How would I do this?
     
    eagle, Sep 6, 2005
    #1
    1. Advertising

  2. Use the FindControl Method.

    Here is an example of what you could do, I'm typing this straight into the
    email without an IDE, so you'll pardon any syntax errors. :)

    Dim dgTemp As New DataGrid
    dgTemp = CType(Page.FindControl("DataGrid1or2or3"), DataGrid)
    dgTemp.DataSource = dt
    dgTemp.DataBind();


    HTH

    -S.M. Altaf
    [MVP - VB]




    --------------------------------------------------------------------------------
    All that glitters has a high refractive index. www.mendhak.com
    "eagle" <> wrote in message
    news:...
    > How can I declare the name of a grid, then use it to bind it to the
    > datasource?
    >
    > I have 3 grids, each with different id's. dgOne, dgTwo, dgThree. I want
    > to be able to do things to each grid. So I need to pass the name of the
    > grid to the GetData procedure. What I have done so far:
    >
    > arrGridNames(1) = "One"
    > arrGridNames(2) = "Two"
    > arrGridNames(3) = "Three"
    >
    > dg = "dg" & arrGridNames(1)
    >
    > so that I come up with dgOne. But of course that is a string, and can't
    > be a datagrid, so when I try to bind it, I get the error: public member
    > 'Datasource" on type 'String' not found.
    >
    > How would I do this?
    >
    >
    >
    >
     
    S.M. Altaf [MVP], Oct 5, 2005
    #2
    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. Girish
    Replies:
    4
    Views:
    672
    Patrick.O.Ige
    Jul 19, 2005
  2. =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=

    How to transfer a value from an Invisible Grid to an visible Grid

    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=, Oct 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    471
    =?Utf-8?B?QXNzYW5LaGFuIElzbWFpbA==?=
    Oct 17, 2005
  3. Danny Tuppeny

    Grouped grid? Or grid within datalist?

    Danny Tuppeny, Oct 27, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    501
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Oct 27, 2005
  4. Marc
    Replies:
    0
    Views:
    454
  5. Josuan
    Replies:
    0
    Views:
    289
    Josuan
    Jun 2, 2008
Loading...

Share This Page