471,601 Members | 1,203 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,601 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 1585

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tim::.. | last post: by
3 posts views Thread by Lyners | last post: by
3 posts views Thread by thebison | last post: by
6 posts views Thread by Steve Hershoff | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by CCCYYYY | last post: by

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.