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

Vaules are null when inserting new records

1 Answer 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christopher Fenton
Top achievements
Rank 1
Christopher Fenton asked on 17 Nov 2010, 01:25 PM
Hi,

I am using the RadGrid control to show some very basic data and allow users to insert new items and edit existing ones. I have had a look at the documentation and demos concerning inserting but I seem to be running into a problem. No matter what I try the new value is returned as null. Please find my code below:

Markup:

<telerik:RadGrid ID="RadGrid_Baskets" runat="server"                            
    AutoGenerateColumns="False"                                                                                                                
    CssClass="basket_grid"
    DataKeyNames="id">
 
    <ClientSettings 
        Selecting-AllowRowSelect="true"                                
        EnablePostBackOnRowClick="true"
        ClientEvents-OnRowClick="RadGrid_Basket_OnRowClick"/>                           
 
    <MasterTableView CommandItemDisplay="Top">
        <Columns>                                                                       
            <telerik:GridBoundColumn
                DataField="name"
                HeaderText="Basket Name"
                UniqueName="name"/>                                                                                   
 
            <telerik:GridTemplateColumn Display="false"
                ReadOnly="true">                                   
                <ItemTemplate>                                           
                    <input type="hidden" id="item_id_hidden_<%#eval("id")%>" class="item_id" value="<%#eval("id")%>" />                       
                </ItemTemplate>                                       
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn>                                   
                <ItemTemplate>                                           
                    <asp:LinkButton ID="ImageButton_Edit" runat="server"
                        CommandName="Edit"                                                                     
                        Text="Edit"                                               
                        Visible='<%#Not IsSystemBasket(Eval("name"))%>'/>
                </ItemTemplate>                                       
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn
                UniqueName="DeleteColumn">                                   
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton_Delete" runat="server"
                        CommandName="Delete"                     
                        ImageUrl="../Objects/CSS/telerik/Grid/Delete.gif"
                        Text="Delete"                                               
                        Visible='<%#Not IsSystemBasket(Eval("name"))%>'/>                                           
                </ItemTemplate>
            </telerik:GridTemplateColumn>                                                                                                                                              
        </Columns>                      
                                                      
    </MasterTableView>                           
 
</telerik:RadGrid>

Code behind:

Protected Sub RadGrid_Basket_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid_Baskets.InsertCommand
 
Dim newItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim editManager As GridEditManager = newItem.EditManager
 
Dim editor As GridTextBoxColumnEditor = editManager.GetColumnEditor(e.Item.OwnerTableView.RenderColumns(2))
 
ItemBaskets.AddBasket(editor.Text)
 
End Sub


My ItemBasket class handles the creation if the basket and all it needs is a name. The problem is that the value is always null and therefore the AddBasket method throws an exception.

I have also tried:

Protected Sub RadGrid_Basket_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid_Baskets.InsertCommand
 
Dim newItem As GridEditableItem = CType(e.Item, GridEditableItem)
 
Dim values As New Hashtable()
 
e.Item.OwnerTableView.ExtractValuesFromItem(values, newItem)
 
ItemBaskets.AddBasket(values("name"))
 
End Sub


Here the value is in the hashtable but it is null again. I am obviously missing something here, advice would be welcome.


Chris

1 Answer, 1 is accepted

Sort by
0
Christopher Fenton
Top achievements
Rank 1
answered on 18 Nov 2010, 11:23 AM
It turns out that I had rebound the data to the grid without realising it.

I suppose sometimes you just need to look at something with a fresh pair of eyes :)
Tags
Grid
Asked by
Christopher Fenton
Top achievements
Rank 1
Answers by
Christopher Fenton
Top achievements
Rank 1
Share this question
or