This is a migrated thread and some comments may be shown as answers.

Serious problem when i try to add a new record

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adigard
Top achievements
Rank 1
Adigard asked on 26 Oct 2011, 10:57 AM
Greetings,

I have a GridTemplateColumn on my grid :

<telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
    <ItemTemplate>
        <asp:HyperLink ID="EditLink" runat="server" Text="Participants"></asp:HyperLink>
    </ItemTemplate>
</telerik:GridTemplateColumn>

When i click on it,the program goes here to send the ID of the row:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 
    if (e.Item is GridDataItem)
    {
 
        HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
        editLink.Attributes["href"] = "#";
        editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["idRDV"], e.Item.ItemIndex);
 
    }
 
 
}

BUT when i try to insert a new record on my grid, the program goes also here and create an ArgumentOutofRangeException

basically, it says : the index is out of range. Must be non-negative and less than the size of the collection. Parameter name: index


Can anyone help me ? thanks in advance

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 28 Oct 2011, 04:44 PM
Hi Adigard,

You could try to add a check whether the item is in edit mode before trying to access parts of its ItemTemplate:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem && !e.Item.IsInEditMode)
    {...}
}

I hope this helps.

Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Adigard
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or