473,756 Members | 8,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 getDataGridRefe rence 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 getDataGridRefe rence() function which tells me what
DataList item contains the "firing" datagrid. What am I doing wrong?

<asp:datalist OnItemDataBound ="OnItemDataBou ndEventHandler"
id="datalist_Pr ojectPhasesReso urces"
Runat="server" DataKeyField="p roject_phase_id _pk">
<ItemTemplate >
<%# DataBinder.Eval (Container.Data Item,
"project_phase_ name").ToString () %>

---------> Here is my nested DataGrid<--------
<asp:datagrid id="grid_Projec tPhasesResource s"
RUNAT="server" DataKeyField="p pr_id_pk"
OnItemDataBound ="dgPROnItemDat aBoundEventHand ler"
OnEditCommand=" pprOnEdit" OnCancelCommand ="pprOnCance l"
OnUpdateCommand ="pprUpdate" >
<Columns>
<asp:BoundColum n DataField="ppr_ id_pk" Visible="False"
Readonly="True" HeaderText=""></asp:BoundColumn >
<ItemTemplate >
<asp:Label Runat="server" ID="lblTotalHou rs" Text='<%#
Convert.ToStrin g(DataBinder.Ev al(Container.Da taItem,
"ppr_project_re source_hours")) %>' />
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox Font-Size="8pt" Font-Name="Arial" Runat="server"
ID="editTotalHo urs" Text='<%#
Convert.ToStrin g(DataBinder.Ev al(Container.Da taItem,
"ppr_project_re source_hours")) %>' />
</EditItemTemplat e>
</asp:TemplateCol umn>
<asp:EditComman dColumn EditText="Edit" CancelText="Can cel"
UpdateText="Sav e"/>
</Columns>
</asp:datagrid>
------> End of nested DataGrid <-----------

</ItemTemplate>
<SeparatorTempl ate>
<br/>
</SeparatorTempla te>
</asp:datalist>
Code Behind event handler for datagrid
.............

//When edit button is clicked, switch to textbox mode
public void pprOnEdit(Objec t source, DataGridCommand EventArgs e)
{
//Get a reference to the Grid in the current DataList row
DataGrid gridSelected = getDataGridRefe rence();

//Set the EditItemIndex to this Grid's item index
gridSelected.Ed itItemIndex = e.Item.ItemInde x;

//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.W ebControls.Data Grid getDataGridRefe rence()
{
DataListItem datalistitem =
datalist_Projec tPhasesResource s.Items[datalist_Projec tPhasesResource s.SelectedIndex];
return (DataGrid)datal istitem.FindCon trol("grid_Proj ectPhasesResour ces");
}



Jan 24 '06 #1
0 1165

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

Similar topics

0
1702
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 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)
3
1580
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. When a user clicks the edit button, I get an error 'Specified Cast Not Valid'. The code that generates the error is: Dim strCompleted As String = CType(e.Item.Cells(6).Controls(1), TextBox).Text
3
2262
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 database has been made in MSDE. My problem is to do with a DataGrid. I have successfully coded the DataGrid so that you can Edit, Update, Cancel. However as my Update Stored Procedure only updates certain columns I would like to make
5
1447
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 ring to constitute a binary number . And obviously we can get 2^n selections , so the question is :
9
5759
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 call it Express for simplicity). I have, to try to simplify things, put the exact same DB on two systems, one running MSDE and one running Express. Both have 2 Ghz processors (one Intel, one AMD), both have a decent amount of RAM (Intel system...
0
1626
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. The codes are too long to post, and not finding a short compilable example, but the following design will give almost all details to specify the problem. Design .... 1) class Point =stores two int x,y
6
1875
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 box: (errored code) Select Case ComboBox2.text Case Is ="Execute Program" 'code to execute program here Case Is ="Other Command that executes code at a certain time" ' code below the same as above except that it works But not my first(this...
4
1848
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 record the data, including the data within the checkboxes, onto another worksheet. I am having a lot of trouble referencing, much less reading the checkboxes. I had used the format control to reference a cell, but this is not what I want. I need...
3
3400
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 http://pages.cpsc.ucalgary.ca/~zongpeng/CPSC231/assignments/A4/a4.pdf def solveRows(): """eliminates solved numbers by row""" for x in range(0, 81, 9): row = puzzle#loops through each row for space in row: #loops through each space if len(space) == 1: #space is...
0
9384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9212
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9779
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8645
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6473
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5247
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.