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

object reference error on Insert command

3 Answers 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 07 Dec 2012, 03:42 PM
HI,

I have added the radgrid and have the insert command. I do not have the ajax added to the page. when a new item is added, item.extractvalues count is empty. How to retrieve the inserted values.
Below is the current code:
<telerik:RadGrid ID="radgrid1" runat="server" EnableViewState="true"
        ShowFooter="True" 
        OnInsertCommand="radgrid1_InsertCommand" 
        OnNeedDataSource="radgrid1_NeedDataSource">
  
        <MasterTableView DataKeyNames="ProductNumber" AutoGenerateColumns="false" EditMode="InPlace"
            CommandItemDisplay="TopAndBottom" CommandItemSettings-AddNewRecordText="Add New Item">           
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                </telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" ConfirmDialogHeight="100px"
                    ConfirmDialogWidth="220px">
                </telerik:GridButtonColumn>
                  
                <telerik:GridTemplateColumn DataField="ProductNumber" HeaderText="Product Number" UniqueName="ProductNumber"
                    Visible="true">
                    <InsertItemTemplate>
                        <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text="">
                        </telerik:RadTextBox>
                    </InsertItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text="">
                        </telerik:RadTextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <telerik:RadTextBox ID="RadtxtPrdNumber" ReadOnly="true" runat="server" Text="" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
  
</Columns>
        </MasterTableView>
        <ClientSettings EnableRowHoverStyle="true">
        </ClientSettings>
    </telerik:RadGrid>

protected void radgrid1_InsertCommand(object sender, GridCommandEventArgs e)
        {
              
                GridEditableItem item = e.Item as GridEditableItem;
                Hashtable values = new Hashtable();
                 
                item.ExtractValues(values);
  
}

How to fix this?
Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Dec 2012, 04:57 AM
Hi,

Here is the sample code that I tried to get new values in InsertCommand.
C#:
protected void RadGrid1_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    GridEditableItem editedItem = e.Item as GridEditableItem;
    Hashtable newValues = new Hashtable();
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
}

Thanks,
Shinu.
0
Venkatesh
Top achievements
Rank 1
answered on 10 Dec 2012, 12:49 PM
HI,
This code is not working for me.
I tried this:
DataTable purchaseOrder = this.PurchaseOrderData;
                                  
GridDataInsertItem item = (GridDataInsertItem)e.Item;
                               
RadTextBox txtProductNumber = (RadTextBox)item.FindControl("RadtxtPrdNumber");
string strProductNumbervalue = txtProductNumber.Text;


I am getting the value for the first row insertion. when i insert the second row, the value is coming as empty.
How to fix this?
Thanks
0
Shinu
Top achievements
Rank 2
answered on 11 Dec 2012, 04:51 AM
Hi,

Unfortunately I cannot replicate the issue at my end. Here is the code that I tried to get new values on insert and update.
aspx:
<telerik:GridTemplateColumn HeaderText="template">
   <EditItemTemplate>
      <telerik:RadTextBox ID="RadtxtPrdNumber" runat="server" Text=""></telerik:RadTextBox>
   </EditItemTemplate>
</telerik:GridTemplateColumn>
C#:
void RadGrid2_InsertCommand(object sender, GridCommandEventArgs e)
{
        GridDataInsertItem item = (GridDataInsertItem)e.Item;
        RadTextBox txt = (RadTextBox)item.FindControl("RadtxtPrdNumber");
        string value = txt.Text;
}
void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
    GridEditableItem editedItem = (GridEditableItem)e.Item;
    RadTextBox txt = (RadTextBox)item.FindControl("RadtxtPrdNumber");
    string value = txt.Text;
}

Thanks,
Shinu.
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Venkatesh
Top achievements
Rank 1
Share this question
or