Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Nested DataGrids

Reply
Thread Tools

Nested DataGrids

 
 
Vishal
Guest
Posts: n/a
 
      11-19-2004
Hello,

I have created a nested datagrid with the help of this
article: http://www.standardio.org/article.aspx?id=155.
Now I need to edit the nested datagrid. I thought that it
was the same task as editing a single datagrid, but it
doesnt seem so. I created a simple edit handler for my
nested datagrid and inserted the following code:

Sub dgNested_Edit(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
dgNested.EditItemIndex = e.Item.ItemIndex
end sub

However I get the error that dgNested is not declared,
although it is. I guess I have to use somehow findcontrol
or anything else to get this working. Anybody has any
experience with editing nested Datagrids?

Thanks

 
Reply With Quote
 
 
 
 
Scott Mitchell [MVP]
Guest
Posts: n/a
 
      11-20-2004
Vishal, are you wiring up the EditCommand to the event handler in your
declarative syntax, like so?

<aspataGrid id="OutterDataGrid" ...>
<Columns>
...
<asp:TemplateColumn>
<ItemTemplate>
<aspataGrid id="InnerDataGrid" OnEditCommand="dgNested_Edit"
.... />
</ItemTemplate>
</asp:TemplateColumn>
...
</Columns>
</aspataGrid>

???

Now, you won't be able to access dgNested directly from the EditCommand
event handler, but the sender parameter passed into the event handler
is, IIRC, the Edit button. Now, you can get to the DataGrid like so
(untested code follows):

Sub dgNested_Edit(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim myInnerDG as DataGrid
Dim myEditButton as Button = CType(sender, Button)

myInnerDG = CType(myEditButton.Parent.Parent.Parent, DataGrid)

myInnerDG.EditItemIndex = ...
end sub


The Button's Parent is the TableCell it exists in. It's Parent is the
DataGridItem. And the DataGridItem's parent is the DataGrid. That's
why we do .Parent.Parent.Parent. Hope this makes sense!


--

Scott Mitchell
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 
Reply With Quote
 
 
 
 
Vishal
Guest
Posts: n/a
 
      11-20-2004
Thanks for the reply Scott. Yes I am doing it this way.
When I use your code and press the edit button then I get
the following error:

System.InvalidCastException: Specified cast is not valid.

What can I do here?

Vishal


>-----Original Message-----
>Vishal, are you wiring up the EditCommand to the event

handler in your
>declarative syntax, like so?
>
><aspataGrid id="OutterDataGrid" ...>
> <Columns>
> ...
> <asp:TemplateColumn>
> <ItemTemplate>
> <aspataGrid id="InnerDataGrid"

OnEditCommand="dgNested_Edit"
>.... />
> </ItemTemplate>
> </asp:TemplateColumn>
> ...
> </Columns>
></aspataGrid>
>
>???
>
>Now, you won't be able to access dgNested directly from

the EditCommand
>event handler, but the sender parameter passed into the

event handler
>is, IIRC, the Edit button. Now, you can get to the

DataGrid like so
>(untested code follows):
>
>Sub dgNested_Edit(ByVal sender As Object, ByVal e As
>DataGridCommandEventArgs)
> Dim myInnerDG as DataGrid
> Dim myEditButton as Button = CType(sender, Button)
>
> myInnerDG = CType(myEditButton.Parent.Parent.Parent,

DataGrid)
>
> myInnerDG.EditItemIndex = ...
>end sub
>
>
>The Button's Parent is the TableCell it exists in. It's

Parent is the
>DataGridItem. And the DataGridItem's parent is the

DataGrid. That's
>why we do .Parent.Parent.Parent. Hope this makes

sense!
>
>
>--
>
> Scott Mitchell
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
>
>* When you think ASP.NET, think 4GuysFromRolla.com!
>.
>

 
Reply With Quote
 
Vishal
Guest
Posts: n/a
 
      11-20-2004
BTW: Isnt the sender the datagrid?


>-----Original Message-----
>Thanks for the reply Scott. Yes I am doing it this way.
>When I use your code and press the edit button then I get
>the following error:
>
>System.InvalidCastException: Specified cast is not valid.
>
>What can I do here?
>
>Vishal
>
>
>>-----Original Message-----
>>Vishal, are you wiring up the EditCommand to the event

>handler in your
>>declarative syntax, like so?
>>
>><aspataGrid id="OutterDataGrid" ...>
>> <Columns>
>> ...
>> <asp:TemplateColumn>
>> <ItemTemplate>
>> <aspataGrid id="InnerDataGrid"

>OnEditCommand="dgNested_Edit"
>>.... />
>> </ItemTemplate>
>> </asp:TemplateColumn>
>> ...
>> </Columns>
>></aspataGrid>
>>
>>???
>>
>>Now, you won't be able to access dgNested directly from

>the EditCommand
>>event handler, but the sender parameter passed into the

>event handler
>>is, IIRC, the Edit button. Now, you can get to the

>DataGrid like so
>>(untested code follows):
>>
>>Sub dgNested_Edit(ByVal sender As Object, ByVal e As
>>DataGridCommandEventArgs)
>> Dim myInnerDG as DataGrid
>> Dim myEditButton as Button = CType(sender, Button)
>>
>> myInnerDG = CType

(myEditButton.Parent.Parent.Parent,
>DataGrid)
>>
>> myInnerDG.EditItemIndex = ...
>>end sub
>>
>>
>>The Button's Parent is the TableCell it exists in. It's

>Parent is the
>>DataGridItem. And the DataGridItem's parent is the

>DataGrid. That's
>>why we do .Parent.Parent.Parent. Hope this makes

>sense!
>>
>>
>>--
>>
>> Scott Mitchell
>> (E-Mail Removed)
>> http://www.4GuysFromRolla.com
>>
>>* When you think ASP.NET, think 4GuysFromRolla.com!
>>.
>>

>.
>

 
Reply With Quote
 
Vishal
Guest
Posts: n/a
 
      11-20-2004
Scott,

I have this code now and it works partially.

Sub dgNested_Edit(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim myInnerDG as DataGrid = sender
response.write(sender.ID)
'Dim myEditButton as Button = CType(sender, Button)
'myInnerDG = CType(myEditButton.Parent.Parent.Parent,
DataGrid)

myInnerDG.EditItemIndex = e.Item.ItemIndex

end sub

However the thing is that when I press the first time the
button then I dont see the datagrid in edit mode. Although
the sender.ID is printer. Now when I press the second
time, then the datagrid is in edit mode. I dont understand
this. Basically the datagrid goes in edit mode when I
click the edit button twice. What can cause such a
behaviour?

Thanks

>-----Original Message-----
>BTW: Isnt the sender the datagrid?
>
>
>>-----Original Message-----
>>Thanks for the reply Scott. Yes I am doing it this way.
>>When I use your code and press the edit button then I

get
>>the following error:
>>
>>System.InvalidCastException: Specified cast is not valid.
>>
>>What can I do here?
>>
>>Vishal
>>
>>
>>>-----Original Message-----
>>>Vishal, are you wiring up the EditCommand to the event

>>handler in your
>>>declarative syntax, like so?
>>>
>>><aspataGrid id="OutterDataGrid" ...>
>>> <Columns>
>>> ...
>>> <asp:TemplateColumn>
>>> <ItemTemplate>
>>> <aspataGrid id="InnerDataGrid"

>>OnEditCommand="dgNested_Edit"
>>>.... />
>>> </ItemTemplate>
>>> </asp:TemplateColumn>
>>> ...
>>> </Columns>
>>></aspataGrid>
>>>
>>>???
>>>
>>>Now, you won't be able to access dgNested directly from

>>the EditCommand
>>>event handler, but the sender parameter passed into the

>>event handler
>>>is, IIRC, the Edit button. Now, you can get to the

>>DataGrid like so
>>>(untested code follows):
>>>
>>>Sub dgNested_Edit(ByVal sender As Object, ByVal e As
>>>DataGridCommandEventArgs)
>>> Dim myInnerDG as DataGrid
>>> Dim myEditButton as Button = CType(sender, Button)
>>>
>>> myInnerDG = CType

>(myEditButton.Parent.Parent.Parent,
>>DataGrid)
>>>
>>> myInnerDG.EditItemIndex = ...
>>>end sub
>>>
>>>
>>>The Button's Parent is the TableCell it exists in.

It's
>>Parent is the
>>>DataGridItem. And the DataGridItem's parent is the

>>DataGrid. That's
>>>why we do .Parent.Parent.Parent. Hope this makes

>>sense!
>>>
>>>
>>>--
>>>
>>> Scott Mitchell
>>> (E-Mail Removed)
>>> http://www.4GuysFromRolla.com
>>>
>>>* When you think ASP.NET, think 4GuysFromRolla.com!
>>>.
>>>

>>.
>>

>.
>

 
Reply With Quote
 
Vishal
Guest
Posts: n/a
 
      11-20-2004
Please help me scott if you can. I am totally stuck since
hours.


>-----Original Message-----
>Vishal, are you wiring up the EditCommand to the event

handler in your
>declarative syntax, like so?
>
><aspataGrid id="OutterDataGrid" ...>
> <Columns>
> ...
> <asp:TemplateColumn>
> <ItemTemplate>
> <aspataGrid id="InnerDataGrid"

OnEditCommand="dgNested_Edit"
>.... />
> </ItemTemplate>
> </asp:TemplateColumn>
> ...
> </Columns>
></aspataGrid>
>
>???
>
>Now, you won't be able to access dgNested directly from

the EditCommand
>event handler, but the sender parameter passed into the

event handler
>is, IIRC, the Edit button. Now, you can get to the

DataGrid like so
>(untested code follows):
>
>Sub dgNested_Edit(ByVal sender As Object, ByVal e As
>DataGridCommandEventArgs)
> Dim myInnerDG as DataGrid
> Dim myEditButton as Button = CType(sender, Button)
>
> myInnerDG = CType(myEditButton.Parent.Parent.Parent,

DataGrid)
>
> myInnerDG.EditItemIndex = ...
>end sub
>
>
>The Button's Parent is the TableCell it exists in. It's

Parent is the
>DataGridItem. And the DataGridItem's parent is the

DataGrid. That's
>why we do .Parent.Parent.Parent. Hope this makes

sense!
>
>
>--
>
> Scott Mitchell
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
>
>* When you think ASP.NET, think 4GuysFromRolla.com!
>.
>

 
Reply With Quote
 
Vishal
Guest
Posts: n/a
 
      11-21-2004
Can somebody help here please?

Vishal.

>-----Original Message-----
>Vishal, are you wiring up the EditCommand to the event

handler in your
>declarative syntax, like so?
>
><aspataGrid id="OutterDataGrid" ...>
> <Columns>
> ...
> <asp:TemplateColumn>
> <ItemTemplate>
> <aspataGrid id="InnerDataGrid"

OnEditCommand="dgNested_Edit"
>.... />
> </ItemTemplate>
> </asp:TemplateColumn>
> ...
> </Columns>
></aspataGrid>
>
>???
>
>Now, you won't be able to access dgNested directly from

the EditCommand
>event handler, but the sender parameter passed into the

event handler
>is, IIRC, the Edit button. Now, you can get to the

DataGrid like so
>(untested code follows):
>
>Sub dgNested_Edit(ByVal sender As Object, ByVal e As
>DataGridCommandEventArgs)
> Dim myInnerDG as DataGrid
> Dim myEditButton as Button = CType(sender, Button)
>
> myInnerDG = CType(myEditButton.Parent.Parent.Parent,

DataGrid)
>
> myInnerDG.EditItemIndex = ...
>end sub
>
>
>The Button's Parent is the TableCell it exists in. It's

Parent is the
>DataGridItem. And the DataGridItem's parent is the

DataGrid. That's
>why we do .Parent.Parent.Parent. Hope this makes

sense!
>
>
>--
>
> Scott Mitchell
> (E-Mail Removed)
> http://www.4GuysFromRolla.com
>
>* When you think ASP.NET, think 4GuysFromRolla.com!
>.
>

 
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
nested datagrids ProgramAnalyst ASP .Net 3 11-05-2004 08:59 PM
Edit Nested Datagrids Dave T ASP .Net 0 11-03-2003 07:08 PM
Nested DataGrids Dave ASP .Net 1 07-21-2003 06:22 PM
Nested DataGrids Dave ASP .Net 1 07-15-2003 05:03 PM
Re: Nested Datagrids Juliano Bortolozzi ASP .Net 0 07-14-2003 05:28 PM



Advertisments