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

extract value radgrid for insert error

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vinamra
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"  
    onitemupdated="RadGrid1_ItemUpdated"  
    oninsertcommand="RadGrid1_InsertCommand"  
    onupdatecommand="RadGrid1_UpdateCommand"
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top"  
        DataKeyNames="Id,title,description,path,data" DataSourceID="SqlDataSource1"
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
    <Columns> 
        <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" HeaderText="Id"  
            ReadOnly="True" SortExpression="Id" UniqueName="Id"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="title" HeaderText="title"  
            SortExpression="title" UniqueName="title"
        </telerik:GridBoundColumn> 
        <telerik:GridBoundColumn DataField="description" HeaderText="description"  
            SortExpression="description" UniqueName="description"
        </telerik:GridBoundColumn> 
        <telerik:GridTemplateColumn DataField="path" HeaderText="Screen Shot"  
            SortExpression="path" UniqueName="path"
            <EditItemTemplate> 
                <asp:TextBox ID="pathTextBox" runat="server" Text='<%# Bind("path") %>'></asp:TextBox> 
            </EditItemTemplate> 
            <ItemTemplate> 
                <asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/Images/thumbs/" +Eval("path") %>' /> 
            </ItemTemplate> 
        </telerik:GridTemplateColumn> 
        <telerik:GridBoundColumn DataField="data" Display="False" HeaderText="data"  
            SortExpression="data" UniqueName="data"
        </telerik:GridBoundColumn> 
        <telerik:GridEditCommandColumn> 
        </telerik:GridEditCommandColumn> 
        <telerik:GridButtonColumn CommandName="Delete" Text="Delete"  
            UniqueName="column"
        </telerik:GridButtonColumn> 
    </Columns> 
    <EditFormSettings> 
        <EditColumn UniqueName="EditCommandColumn1"
        </EditColumn> 
    </EditFormSettings> 
</MasterTableView> 
 
<FilterMenu EnableTheming="True"
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
</telerik:RadGrid> 
<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"
    <DeleteParameters> 
        <asp:Parameter Name="Id" Type="Int32" /> 
    </DeleteParameters> 
    <InsertParameters> 
        <asp:Parameter Name="title" Type="String" /> 
        <asp:Parameter Name="description" Type="String" /> 
        <asp:Parameter Name="path" Type="String" /> 
        <asp:Parameter Name="data" Type="String" /> 
    </InsertParameters> 
    <UpdateParameters> 
        <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" /> 
    </UpdateParameters> 
</asp:SqlDataSource> 
 
i am using radcontrols ajax Q2
plz help urget thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
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,
Daniel
the Telerik team

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