Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Nested Datagrid reference?

Reply
Thread Tools

Nested Datagrid reference?

 
 
Tim
Guest
Posts: n/a
 
      01-05-2004
I have a datagrid that is nested inside of another datagrid. The code
is below.

The datagrids display correctly, however, I cannot edit the inner
datagrid as I haven't been able to correctly reference it. The Edit
command is also below.

How can I correctly reference the inner datagrid to edit it?

Thanks,
Tim


<aspatagrid... >
<asp:BoundColumn ...>
<asp:BoundColumn ...>
<asp:TemplateColumn>
<ItemTemplate>
<aspataGrid runat="server" id="dgSub"
OnEditCommand="dgSub_Edit"
DataSource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("GroupNameRelations")
%>'>
<asp:TemplateColumn HeaderText="Local Group Name">
<ItemTemplate>
<%# DataBinder.Evalontainer.DataItem, "LocalGroupName")
%> </ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtLocalGroupName" Runat="server"
Text='<% DataBinder.Eval(Container.DataItem, "LocalGroupName") %>'
/> </EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Button ID="btnLocalEdit" Runat="server"
CommandName="Edit" Text="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnLocalUpdate" Runat="server"
CommandName="Update" Text="Update" />
<asp:Button ID="btnLocalCancel" Runat="server"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
</asp:TemplateColumn>
</aspataGrid>
</aspataGrid>

The edit command currently looks like:
protected void dgLocalGroups_Edit(object sender,
DataGridCommandEventArgs e)
{
DataGrid dgLocalGroups =
(DataGrid)dgGroups.FindControl("dgLocalGroups");
// get the row that was clicked
int intRow = e.Item.ItemIndex;
dgLocalGroups.EditItemIndex = intRow;
}
 
Reply With Quote
 
 
 
 
Alvin Bruney
Guest
Posts: n/a
 
      01-05-2004
The datagrid can only be nested if its added to the parent control as a
child control. So what you need to do is find the parent control and then
iterate thru its collection of child controls. The findcontrol here will do
most of the work. You need to know what level you are at so that you can
cast correctly otherwise you will get a cast error. What problems are you
experiencing?

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/2bz4t
"Tim" <> wrote in message
news: om...
> I have a datagrid that is nested inside of another datagrid. The code
> is below.
>
> The datagrids display correctly, however, I cannot edit the inner
> datagrid as I haven't been able to correctly reference it. The Edit
> command is also below.
>
> How can I correctly reference the inner datagrid to edit it?
>
> Thanks,
> Tim
>
>
> <aspatagrid... >
> <asp:BoundColumn ...>
> <asp:BoundColumn ...>
> <asp:TemplateColumn>
> <ItemTemplate>
> <aspataGrid runat="server" id="dgSub"
> OnEditCommand="dgSub_Edit"
> DataSource='<%#
> ((DataRowView)Container.DataItem).Row.GetChildRows ("GroupNameRelations")
> %>'>
> <asp:TemplateColumn HeaderText="Local Group Name">
> <ItemTemplate>
> <%# DataBinder.Evalontainer.DataItem, "LocalGroupName")
> %> </ItemTemplate>
> <EditItemTemplate>
> <asp:TextBox ID="txtLocalGroupName" Runat="server"
> Text='<% DataBinder.Eval(Container.DataItem, "LocalGroupName") %>'
> /> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:Button ID="btnLocalEdit" Runat="server"
> CommandName="Edit" Text="Edit" />
> </ItemTemplate>
> <EditItemTemplate>
> <asp:Button ID="btnLocalUpdate" Runat="server"
> CommandName="Update" Text="Update" />
> <asp:Button ID="btnLocalCancel" Runat="server"
> CommandName="Cancel" Text="Cancel" />
> </EditItemTemplate>
> </asp:TemplateColumn>
> </aspataGrid>
> </aspataGrid>
>
> The edit command currently looks like:
> protected void dgLocalGroups_Edit(object sender,
> DataGridCommandEventArgs e)
> {
> DataGrid dgLocalGroups =
> (DataGrid)dgGroups.FindControl("dgLocalGroups");
> // get the row that was clicked
> int intRow = e.Item.ItemIndex;
> dgLocalGroups.EditItemIndex = intRow;
> }



 
Reply With Quote
 
 
 
 
Tim Cavins
Guest
Posts: n/a
 
      01-05-2004
My problem is that when I click on the Edit button for an item in the
inner datagrid, I get the following error:

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

This is on the line where I set the EditItemIndex for the inner
datagrid.

So, I don't have the reference set up correctly in order to use the
inner datagrid.

Can you help with that?

-Tim



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Alvin Bruney
Guest
Posts: n/a
 
      01-06-2004
you are going to have to post the relevant code at least for the itemcommand
handler or edit handler. Just the relevant portions. I've some ideas about
what might be wrong but i won't speculate without further inspection.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/2bz4t
"Tim Cavins" <> wrote in message
news:%...
> My problem is that when I click on the Edit button for an item in the
> inner datagrid, I get the following error:
>
> Exception Details: System.NullReferenceException: Object reference not
> set to an instance of an object.
>
> This is on the line where I set the EditItemIndex for the inner
> datagrid.
>
> So, I don't have the reference set up correctly in order to use the
> inner datagrid.
>
> Can you help with that?
>
> -Tim
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Tim Cavins
Guest
Posts: n/a
 
      01-06-2004
Here is the same code as posted in my first comment. The datagrid code
is first, then below that is my OnEditCommand code.

<aspatagrid... >
<asp:BoundColumn ...>
<asp:BoundColumn ...>
<asp:templatecolumn>
<itemtemplate>
<aspataGrid runat="server" id="dgSub"
OnEditCommand="dgSub_Edit"
datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows ("GroupNameRelations")
%>'>
<asp:TemplateColumn HeaderText="Local Group name">
<itemtemplate>
<%# DataBinder.Evalontainer.DataItem, "LocalGroupName")
%> </itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtLocalGroupName" Runat="server"
text='<% DataBinder.Eval(Container.DataItem, "LocalGroupName") %>'
/> </edititemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:Button ID="btnLocalEdit" Runat="server"
CommandName="Edit" Text="Edit" />
</itemtemplate>
<edititemtemplate>
<asp:Button ID="btnLocalUpdate" Runat="server"
CommandName="Update" Text="Update" />
<asp:Button ID="btnLocalCancel" Runat="server"
CommandName="Cancel" Text="Cancel" />
</edititemtemplate>
</asp:templatecolumn>
</asp:datagrid>
</asp:datagrid>

The edit command currently looks like:

protected void dgLocalGroups_Edit(object sender,
DataGridCommandEventArgs e)
{
DataGrid dgLocalGroups =
(DataGrid)dgGroups.FindControl("dgLocalGroups");
// get the row that was clicked
int intRow = e.Item.ItemIndex;
dgLocalGroups.EditItemIndex = intRow;
}

-Tim


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Douglas J. Badin
Guest
Posts: n/a
 
      01-09-2004
In general, maybe taking a different approach would help. It cleared up a
number of different problems, especially editing being able to edit the
sub-grid.

Put you nested DataGrid in a Web User Control and relate the Parent Grid to
the Child Grid via properties. This way you get a seperate set of events
for the Child Grid.

Doug

"Tim" <> wrote in message
news: om...
> I have a datagrid that is nested inside of another datagrid. The code
> is below.
>
> The datagrids display correctly, however, I cannot edit the inner
> datagrid as I haven't been able to correctly reference it. The Edit
> command is also below.
>
> How can I correctly reference the inner datagrid to edit it?
>
> Thanks,
> Tim
>
>
> <aspatagrid... >
> <asp:BoundColumn ...>
> <asp:BoundColumn ...>
> <asp:TemplateColumn>
> <ItemTemplate>
> <aspataGrid runat="server" id="dgSub"
> OnEditCommand="dgSub_Edit"
> DataSource='<%#
> ((DataRowView)Container.DataItem).Row.GetChildRows ("GroupNameRelations")
> %>'>
> <asp:TemplateColumn HeaderText="Local Group Name">
> <ItemTemplate>
> <%# DataBinder.Evalontainer.DataItem, "LocalGroupName")
> %> </ItemTemplate>
> <EditItemTemplate>
> <asp:TextBox ID="txtLocalGroupName" Runat="server"
> Text='<% DataBinder.Eval(Container.DataItem, "LocalGroupName") %>'
> /> </EditItemTemplate>
> </asp:TemplateColumn>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:Button ID="btnLocalEdit" Runat="server"
> CommandName="Edit" Text="Edit" />
> </ItemTemplate>
> <EditItemTemplate>
> <asp:Button ID="btnLocalUpdate" Runat="server"
> CommandName="Update" Text="Update" />
> <asp:Button ID="btnLocalCancel" Runat="server"
> CommandName="Cancel" Text="Cancel" />
> </EditItemTemplate>
> </asp:TemplateColumn>
> </aspataGrid>
> </aspataGrid>
>
> The edit command currently looks like:
> protected void dgLocalGroups_Edit(object sender,
> DataGridCommandEventArgs e)
> {
> DataGrid dgLocalGroups =
> (DataGrid)dgGroups.FindControl("dgLocalGroups");
> // get the row that was clicked
> int intRow = e.Item.ItemIndex;
> dgLocalGroups.EditItemIndex = intRow;
> }



 
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
How does a nested datagrid reference parent row in master datagrid? John Dalberg ASP .Net Datagrid Control 1 12-20-2005 06:45 PM
problem in nesting datagrid in to a nested datagrid sajvargs ASP .Net 0 02-20-2005 12:17 AM
Nested iterators (well, not nested exactly...) Russ Perry Jr Java 2 08-20-2004 06:51 PM
Editing a datagrid nested within another datagrid uk00121 ASP .Net Datagrid Control 2 04-19-2004 02:17 PM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57