Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GridView in a GridView

4 views
Skip to first unread message

Nalaka

unread,
Nov 10, 2005, 7:07:27 PM11/10/05
to
Hi,
I have a gridView (grid1), which as a templateColumn.
In the template column, I have put in a gridView (grid2) and a
ObjectDataSource (objectDataSource2).

Question is... How to I pass the current_row_key of Grid1... to the
objectDataSource2 parameter?
(so that the second grid, gets only the information to do with current row
of grid1)


any help is deeply appreciated...

Thanks
Nalaka


timkling

unread,
Nov 10, 2005, 8:36:04 PM11/10/05
to
Hi Nalaka,

It's actually pretty simple once you grasp the concept. I can help you with
code if you want to try it. You have to use code--you can't specify the
DataSource declaritively (in the markup).

In the template column, add a Label (with the visible property set to
false). Bind that to the key. After you call DataBind() on the first
DataGrid, you loop through the first DataGrid's Items and use FindControl()
to get a reference to the child grid, and again to get a reference to the
label. Now, use your Label.Text to get the id and use that with your object
to get the DataSource for the child grid.

Some people don't catch on until they see it in action, but if you get it
let me know what type of DataSource you are using (DataSet, DataTable,
object) and I will give you a little bit of code.

Tim

timkling

unread,
Nov 10, 2005, 8:41:05 PM11/10/05
to
Oops. I didn't read close enough. You are using 2.0 aren't you? There may
be an easier way in 2.0, I don't get it until next month!

If you want to do it the 1.1 way the concept should still work.

Tim

Steven Cheng[MSFT]

unread,
Nov 11, 2005, 2:25:38 AM11/11/05
to
Hi Nalaka,

As for your question on displaying Nested GridView which has relation ships
between the binding datas. I think you can consider the following means:

We can put an invisible label or TextBox control in the templateField where
we'll also put the Nested GridView and sub DataSource control. Then, the
invisible Label or TextBox's Text property will be binded to parent
GridView's Key Column value(we can do this through IDEs' wizard ---- Edit
Template.....). After that, we configure the Sub DataSource control in the
template field, and add a control parameter for its "Where ...." sql
statement, and specify the invisible Label or Textbox as the control
source. Then, bind the nested GridView to the sub DataSource and run the
page, that'll display the nested GridViews we expected.

Actually I've tested with the NorthWind's Orders and OrderDetails tables
and works well.(I've even tested three level nested and also works :)).
However, one important things we need to take care, such template databound
control(GridView, DataList....) all store the binded datas in ViewState
which may make the page's size extremely huge. You'd take care of this to
see whether it's appropriate according to the target environment's network
bandwidth.

If there're anything unclear, please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


--------------------
| From: "Nalaka" <nala...@nospam.nospam>
| Subject: GridView in a GridView
| Date: Thu, 10 Nov 2005 16:07:27 -0800
| Lines: 17
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <esnJoPl5...@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: m181-9.bctransit.bc.ca 199.60.181.9
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:357227
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Nalaka

unread,
Nov 14, 2005, 12:57:54 PM11/14/05
to
Hi Tim,
Ok... I created a label (label_key) in the template field... and set the
value to outerGrid.key
(using Eval("key")).....
It works fine, now I can see the key in the inner template column.

Now the question is... I need to tell the "ObjectDataSource" of the
innerGrid (inside template field),
that the parameter is the text value of label_key.

at what point (which event), can I do this, and how do I do this......

yes... I can use your code sample....


Thanks
Nalaka


"timkling" <timk...@discussions.microsoft.com> wrote in message
news:7F422E1D-6E2E-4595...@microsoft.com...

Carlos Albert

unread,
Dec 5, 2005, 11:43:33 AM12/5/05
to
Hello Steven, took some time for me to find this thear, but here I am =)

I have the same situation: a Gridview inside another Gridview. With the
difference is that I usually work from the codehind because I get some of
the info (XML mostly) from shared libraries. And I can debug it. And the
code is protected. Can this be done the same way? Gridview inside a gridview
from the codehind?

If not, tecnically I could use the datasource wizard since I could populate
all this gridview from a SQL connection, but I find this little problem: I
used the datasource wizard for the 'parent' gridview (never used it before).
All just fine, the test gives me back the records, etc, etc. But when I test
it, doesn't return any gridview at all =S

Didn't even start with the 'child' gridview...

Please, could you give me some help here? =$

"Steven Cheng[MSFT]" <stc...@online.microsoft.com> escribió en el mensaje
news:oZ6poEp...@TK2MSFTNGXA02.phx.gbl...

Nalaka

unread,
Dec 5, 2005, 12:48:50 PM12/5/05
to
Hi,
try this....
in the same templateField as inner GridView, put a invisible textbox above
the gridview.
use the text box eval("id") to bind to the outer grid.

set the inner grid view select parameter to the invisible textbox control
.....

see if this works...
if not I have a more complicated work around that works for sure.
Only after doing that I realized that above may be much simpler.

Thanks
Nalaka


"Carlos Albert" <nadie@ningunlugar> wrote in message
news:ug6Y9rb%23FH...@TK2MSFTNGP12.phx.gbl...

0 new messages