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

Error "Cannot find a cell bound to column name" when updatecommand is called

1 Answer 596 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 11 Dec 2012, 05:28 AM
HI,
I have the rad grid in which i have the edit item template. The aspx is as follows:
<telerik:RadGrid ID="radgrid1" runat="server" 
        EnableViewState="true" ShowStatusBar="true" AllowAutomaticUpdates="false"
        ShowFooter="True" 
        OnInsertCommand="radgrid1_InsertCommand" OnUpdateCommand="radgrid1_UpdateCommand"
        OnNeedDataSource="radgrid1_NeedDataSource"  >
        <MasterTableView DataKeyNames="ProductNumber" AutoGenerateColumns="false" EditMode="InPlace"
            CommandItemDisplay="TopAndBottom" CommandItemSettings-AddNewRecordText="Add New Purchase Order">           
            <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='<%# Eval("ProductNumber") %>'>
</telerik:RadTextBox>
</EditItemTemplate>
  
                    <ItemTemplate>
<telerik:RadTextBox ID="RadtxtPrdNumber" ReadOnly="true" runat="server" Text='<%# Eval("ProductNumber") %>' />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

In the update command, i am trying to access the column as below:
GridEditableItem editedItem = e.Item as GridEditableItem;
               //Get the primary key value using the DataKeyValue.      
               string ProductID = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProductNumber"].ToString();
               //Access the textbox from the edit form template and store the values in string variables.   
               string strProductNumbervalue = (editedItem["RadtxtPrdNumber"].Controls[0] as RadTextBox).Text;

I am getting the error as "Cannot find a cell bound to column name 'RadtxtPrdNumber', when the code hits "string strProductNumbervalue".
How to fix this?
Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Dec 2012, 05:36 AM
Hi,

You can try the following approach to access boundcolumns and templatecolumns.
C#:
protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
  GridEditableItem editedItem = (GridEditableItem)e.Item;
  TextBox txt = (TextBox)editedItem["Uniquename"].Controls[0];//accessing boundcolumns
  RadTextBox radtxt = (RadTextBox)editedItem.FindControl("RadtxtPrdNumber");//accessing controls in template columns
}

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