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

extract value radgrid for insert error

1 Answer 59 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
vinamra asked on 01 Nov 2008, 07:41 PM
hi i am facing problem in RadGrid1_InsertCommand

i want to extracts the values entered by the user .
so i am using following code
GridEditableItem editedItem = e.Item as GridEditableItem; 
Hashtable newValues = new Hashtable(); 
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem); 

now the 'newvalues' contains 0 elements.
i checked  the editeditem.keyvalues. it shows this error msg 'editedItem.KeyValues' threw an exception of type 'System.ArgumentOutOfRangeException'

but when i use same code in RadGrid1_InsertCommand
it shows the excat values what i want.

my markup is as follows
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Video.ascx.cs" Inherits="Admin_Controls_Video" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True"  
    AllowAutomaticInserts="false" AllowAutomaticUpdates="false"  
    DataSourceID="SqlDataSource1" GridLines="None"  
    onitemdeleted="RadGrid1_ItemDeleted" oniteminserted="RadGrid1_ItemInserted"  
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top"  
        DataKeyNames="Id,title,description,path,data" DataSourceID="SqlDataSource1"
<HeaderStyle Width="20px"></HeaderStyle> 
<HeaderStyle Width="20px"></HeaderStyle> 
        <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" HeaderText="Id"  
            ReadOnly="True" SortExpression="Id" UniqueName="Id"
        <telerik:GridBoundColumn DataField="title" HeaderText="title"  
            SortExpression="title" UniqueName="title"
        <telerik:GridBoundColumn DataField="description" HeaderText="description"  
            SortExpression="description" UniqueName="description"
        <telerik:GridTemplateColumn DataField="path" HeaderText="Screen Shot"  
            SortExpression="path" UniqueName="path"
                <asp:TextBox ID="pathTextBox" runat="server" Text='<%# Bind("path") %>'></asp:TextBox> 
                <asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/Images/thumbs/" +Eval("path") %>' /> 
        <telerik:GridBoundColumn DataField="data" Display="False" HeaderText="data"  
            SortExpression="data" UniqueName="data"
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete"  
        <EditColumn UniqueName="EditCommandColumn1"
<FilterMenu EnableTheming="True"
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
<asp:SqlDataSource ID="SqlDataSource1" runat="server"  
    ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString1 %>"  
    DeleteCommand="DELETE FROM [Video] WHERE [Id] = @Id"  
    InsertCommand="INSERT INTO [Video] ([title], [description], [path], [data]) VALUES (@title, @description, @path, @data)"  
    ProviderName="<%$ ConnectionStrings:ASPNETDBConnectionString1.ProviderName %>"  
    SelectCommand="SELECT [Id], [title], [description], [path], [data] FROM [Video]"  
    UpdateCommand="UPDATE [Video] SET [title] = @title, [description] = @description, [path] = @path, [data] = @data WHERE [Id] = @Id"
        <asp:Parameter Name="Id" Type="Int32" /> 
        <asp:Parameter Name="title" Type="String" /> 
        <asp:Parameter Name="description" Type="String" /> 
        <asp:Parameter Name="path" Type="String" /> 
        <asp:Parameter Name="data" Type="String" /> 
        <asp:Parameter Name="title" Type="String" /> 
        <asp:Parameter Name="description" Type="String" /> 
        <asp:Parameter Name="path" Type="String" /> 
        <asp:Parameter Name="data" Type="String" /> 
        <asp:Parameter Name="Id" Type="Int32" /> 
i am using radcontrols ajax Q2
plz help urget thanks

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 03 Nov 2008, 10:50 AM
Hello Vinamra,

I suppose you are trying to get the KeyValues of the item before they are actually populated by your Sql server (when using AutoIncrement). You can get the desired values after you performed your Insert command in the same handler:
Alternatives to @@IDENTITY

Kind regards,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question