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

GridEditCommandColumn Problems

1 Answer 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pete
Top achievements
Rank 1
Pete asked on 05 Dec 2011, 01:57 PM
Hey,

Dynamically adding GridEditCommandColumns to my Grid in attempt to be able to edit chosen lines in a grid. The code to add them is below.
If ViewState("MasterEdit") Is Nothing Or Not ViewState("MasterEdit") = True Then
    Dim editCol As GridEditCommandColumn
    editCol = New GridEditCommandColumn
    editCol.UniqueName = "MasterEditColumn"
    editCol.HeaderText = ""
    editCol.HeaderStyle.Width = 20
    editCol.ButtonType = GridButtonColumnType.ImageButton
    editCol.EditImageUrl = "~\img\edit.gif"
    editCol.EditFormColumnIndex = 0
    rgdTable.MasterTableView.Columns.Add(editCol)
    ViewState.Add("MasterEdit", True)
End If

I do the same thing for the DetailTables. The problem I get is on the DetailTables the column just disappears entirely and on the MasterTable I get the following error:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred because a control with id 'ctl00$CPH1$ValueAddInfo$rgdTable$ctl00$ctl04$EditButton' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.

There doesn't seem to be any way to set the ID of the controls, so I can't take the advice that the error message suggests.

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 08 Dec 2011, 11:21 AM
Hello Pete,

When creating RadGrid on Page_Load event, the columns or detail tables should be added to the corresponding collection first and then values for the properties of this instance should be set. I have modified the code and pasted it below. Additionally, you could go through the Programmatic Creation section in the help article below:
If ViewState("MasterEdit") Is Nothing Or Not ViewState("MasterEdit") = True Then
    Dim editCol As GridEditCommandColumn
    editCol = New GridEditCommandColumn
    rgdTable.MasterTableView.Columns.Add(editCol)
    editCol.UniqueName = "MasterEditColumn"
    editCol.HeaderText = ""
    editCol.HeaderStyle.Width = 20
    editCol.ButtonType = GridButtonColumnType.ImageButton
    editCol.EditImageUrl = "~\img\edit.gif"
    editCol.EditFormColumnIndex = 0
    ViewState.Add("MasterEdit", True)
End If

All the best,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Pete
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or