473,578 Members | 3,279 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 1153

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

Similar topics

0
1689
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...
3
1571
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 =...
3
2257
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....
5
1441
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
5747
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...
0
1615
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...
6
1866
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...
4
1837
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...
3
3388
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...
0
7847
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...
0
8290
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...
0
8148
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6522
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...
0
3781
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1389
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1113
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.