473,396 Members | 1,827 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,396 software developers and data experts.

Problem Referencing OnEditCommand: Index out of Range

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 1141

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

Similar topics

0
by: Chris | 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: tjonsek | last post by:
am working on code that will allow users to update data within the datagrid. I have come across a few problems, some of them I have been able to work out, but this last one is giving me trouble. ...
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: Bo Yang | last post by:
Hi , I have writen a python program to slove a problem described as below: (Forgive my poor English !) Put the 2^n 0 or 1 to form a ring , and we can select any continuous n ones from the...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
0
by: toton | last post by:
Hi, I have a complex design of some dynamic situation. First I am posting the design, then a few questions regarding the problem I am facing. Hope some of the experts will answer the questions....
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
4
by: lindabaldwin | last post by:
Hello all, I am fairly new to VBA and have had limited work with checkboxes before. I have turned an Excel worksheet into a form in which users can enter data and click checkboxes. I want to...
3
by: Ri0o | last post by:
hi, i have to make a sudoku solver using python quickdraw, i've started on it and this is what i got so far here is the link to the assignment...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.