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

JavaScript Error Entering Edit Mode

3 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 26 Nov 2013, 04:46 PM
In my grid if I set the DataKeyName field ReadOnly to "true" so it cannot be edited when I click a row to enter edit mode I get this error,
Unhandled exception at line 885, column 13 in http://localhost:59512/ScriptResource.axd?d=j9g8KwFmyomCksH8Wgu8D921e69mOXBSgcRNM_TYTpo8fsl9bB8knaOk3eJy7i5Vsb6eNonPd3OAqh2MBYPCrNV52HuzPz2Aa-oyIrtDhXd-WOK9m-TImS6nd3inJNNp1xw6jnQGAvJnKfjurTJifqmDUI5njfi6aRYOERJTLDf7VE7Tms_H7Dr6lpjgTT2J0&t=6119e399

0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Value cannot be null.

Parameter name: g


If I do not set the DataKeyName field ReadOnly="true" I do not get this error, but the field is shown and editable in the edit popup.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Nov 2013, 08:37 AM
Hi Bruce,

Below is a sample code snippet that i tried, but i couldn't replicate the issue you have mentioned. Please provide your code snippet so as to identify the issue.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateEditColumn="true" >
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top" EditMode="PopUp">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID"
                   ReadOnly
="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Bruce
Top achievements
Rank 1
answered on 27 Nov 2013, 03:48 PM
Here is the code as I have it now. I supply a list object in the NeedDataSource event. I found a work around last night where I can find and set the Id
fields visibility to false in the ItemDataBoundEvent.

<
telerik:RadGrid ID="uxAGRSSUrethaneDetails" runat="server"
    AutoGenerateColumns="false"
    OnNeedDataSource="uxAGRSSUrethaneDetails_NeedDataSource"
    OnItemDataBound="uxAGRSSUrethaneDetails_ItemDataBound"
    OnUpdateCommand="uxAGRSSUrethaneDetails_UpdateCommand"
    Width="100%"
    Skin="WebBlue">
    <MasterTableView EditMode="PopUp" DataKeyNames="AgrssDetailId, AgrssId">
        <Columns>
            <telerik:GridBoundColumn DataField="AgrssDetailId" DataType="System.Guid" HeaderText="AgrssDetailId" Display="false"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AgrssId" DataType="System.Guid" HeaderText="AgrssId" Display="false"> </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="NagsHwId" DataType="System.String" HeaderText="NAGS Hwd ID" Display="true"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="MfrHwId" DataType="System.String" HeaderText="Mfr Hwd ID" Display="true"></telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="AdhesiveExpDate" DataType="System.DateTime" DataFormatString="{0:M/dd/yyyy}" HeaderText="Adh. Exp. Date" Display="true"></telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="AdhesiveLotNumber" DataType="System.String" HeaderText="Adh. Lot #" Display="true"></telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="SealantExpDate" DataType="System.DateTime" DataFormatString="{0:M/dd/yyyy}" HeaderText="Snt. Exp. Date" Display="true"></telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="SealantLotNumber" DataType="System.String" HeaderText="Snt. Lot #" Display="true" ItemStyle-Width="150px"></telerik:GridBoundColumn>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="AGRSSEditDetailCommandColumn" HeaderText="Edit">
                <ItemStyle Width="30px" HorizontalAlign="Center" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Delete" HeaderText="Delete" UniqueName="AGRSSEditDetailCommandColumn" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to delete this item?">
                <ItemStyle Width="30px" HorizontalAlign="Center" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings EditFormType="AutoGenerated"
            CaptionDataField="NagsHwId">
            <PopUpSettings Modal="true" />
            </EditFormSettings>
    </MasterTableView>
</telerik:RadGrid>

code behind file
protected void uxAGRSSUrethaneDetails_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        if ((e.Item is GridEditFormItem && e.Item.IsInEditMode) && !(e.Item is GridEditFormInsertItem)) // hide the control in edit mode
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            TextBox txt = (TextBox)editItem["AgrssDetailId"].Controls[0];
            txt.Parent.Parent.Visible = false;
            txt = (TextBox)editItem["AgrssId"].Controls[0];
            txt.Parent.Parent.Visible = false;
            txt = (TextBox)editItem["NagsHwId"].Controls[0];
            txt.Parent.Parent.Visible = false;
        }
    }
}
0
Princy
Top achievements
Rank 2
answered on 28 Nov 2013, 03:55 AM
Hi Bruce,

If you set ReadOnly property of a column to true, it will not be available for edit or insert. If you want to hide the column for edit only, please try the following code snippet.

C#:
protected void uxAGRSSUrethaneDetails_ItemDataBound(object sender, GridItemEventArgs e)
 {
    if (e.Item is GridEditableItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditableItem editItem = (GridEditableItem)e.Item;
        editItem["AgrssDetailId"].Parent.Visible = false;          
    }       
 }

Thanks,
Princy
Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bruce
Top achievements
Rank 1
Share this question
or