Declaring the name of a grid

E

eagle

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

S.M. Altaf [MVP]

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]
 

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
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top