473,378 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

OnEditCommand : Nested DataGrid referencing : Code included

I've been searching all over and think I am close, but keep getting the
error "Index out of range" when trying to reference a nested datagrid when
an OnEditCommand event is raised.

When the OnEditCommand event is raised, I try to do the following:

1. Find the selected datalist item in which the nested datagrid raised the
event. (by calling getDataGridReference and returning the DataList's
selectedIndex)

2. Once I know the selected datalist item, find the datagrid control within
that datalist item and set the selected row to edit mode.

The error occurs in my getDataGridReference() function which tells me what
DataList item contains the "firing" datagrid. What am I doing wrong?

<asp:datalist OnItemDataBound="OnItemDataBoundEventHandler"
id="datalist_ProjectPhasesResources"
Runat="server" DataKeyField="project_phase_id_pk">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
"project_phase_name").ToString() %>

---------> Here is my nested DataGrid<--------
<asp:datagrid id="grid_ProjectPhasesResources"
RUNAT="server" DataKeyField="ppr_id_pk"
OnItemDataBound="dgPROnItemDataBoundEventHandler"
OnEditCommand="pprOnEdit" OnCancelCommand="pprOnCancel"
OnUpdateCommand="pprUpdate">
<Columns>
<asp:BoundColumn DataField="ppr_id_pk" Visible="False"
Readonly="True" HeaderText=""></asp:BoundColumn>
<ItemTemplate>
<asp:Label Runat="server" ID="lblTotalHours" Text='<%#
Convert.ToString(DataBinder.Eval(Container.DataIte m,
"ppr_project_resource_hours"))%>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Font-Size="8pt" Font-Name="Arial" Runat="server"
ID="editTotalHours" Text='<%#
Convert.ToString(DataBinder.Eval(Container.DataIte m,
"ppr_project_resource_hours"))%>' />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel"
UpdateText="Save"/>
</Columns>
</asp:datagrid>
------> End of nested DataGrid <-----------

</ItemTemplate>
<SeparatorTemplate>
<br/>
</SeparatorTemplate>
</asp:datalist>
Code Behind event handler for datagrid
.............

//When edit button is clicked, switch to textbox mode
public void pprOnEdit(Object source, DataGridCommandEventArgs e)
{
//Get a reference to the Grid in the current DataList row
DataGrid gridSelected = getDataGridReference();

//Set the EditItemIndex to this Grid's item index
gridSelected.EditItemIndex = e.Item.ItemIndex;

//Call function to bind the grid again
BindGrid();
}
//Get the selected DataList item index so we can find the current DataGrid
item to edit
public System.Web.UI.WebControls.DataGrid getDataGridReference()
{
DataListItem datalistitem =
datalist_ProjectPhasesResources.Items[datalist_ProjectPhasesResources.SelectedIndex];
return (DataGrid)datalistitem.FindControl("grid_ProjectPh asesResources");
}




Jan 24 '06 #1
0 1667

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
0
by: Tim::.. | last post by:
Why doesn't my onEditCommand work??? I don't get an error it just doesn't do the page redirect as requested... Thanks ...CODE.. Sub LinkButton_OnClick(ByVal sender As Object, ByVal e As...
3
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. ...
0
by: ElGordo | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
3
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
1
by: johnlim20088 | last post by:
Hi, Hi, i have a datagrid in my mypage.aspx, I used the Bound column consisted of Edit, Save, Cancel, button. When I press edit, my datagrid change to editable mode, which the Save and Cancel...
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.