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

Problems with creating dynamic columns

3 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 2
Stefan asked on 19 Jun 2013, 09:24 PM
I have a radgrid I am creating dynmically including an editcolumn but when I click on the edit Column button I get the following error?

"An error has occurred because a control with id 'dgCompGrid$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."

I have changed the grids viewstate = True but still get the same error?

        With dgCompGrid
            .Columns.Clear()
            .DataSource = Nothing
            .EnableViewState = True
            .DataSource = ippService.Select(ID)
        End With

        Dim oEditColumn As New GridEditCommandColumn
        With oEditColumn
            .ButtonType = GridButtonColumnType.ImageButton
            .UniqueName = "EditColumn"
            .CancelImageUrl = "~/Images/small/x_out.gif"
            .EditImageUrl = "~/Images/small/pencil.gif"
            .UpdateImageUrl = "~/Images/small/save_blue.gif"
            .ItemStyle.Wrap = False
        End With

        dgCompGrid.MasterTableView.Columns.Add(oEditColumn)


If I comment out the buttontype were the column shows EDIT instead of an image button it have no problems?

I use the Needdatasource to call a sub that loads the data.

Thanks in Advance.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 20 Jun 2013, 11:56 AM
Hi Stefan,

I have tried to replicate your code,the error is occurring because you have added dgCompGrid.MasterTableView.Columns.Add(oEditColumn) at the end.
Please try the following code.

VB:
Dim editcolumn As GridEditCommandColumn
editcolumn = New GridEditCommandColumn()
RadGrid1.MasterTableView.Columns.Add(editcolumn)
editcolumn.ButtonType = GridButtonColumnType.ImageButton
editcolumn.EditImageUrl = "~/Image/free-vector-arrow-icons_f1.jpg"
editcolumn.CancelImageUrl = "~/Image/free-vector-arrow-icons_f2.jpg"
editcolumn.UpdateImageUrl = "~/Image/free-vector-arrow-icons_f3.jpg"
editcolumn.UniqueName = "EditColumn"
editcolumn.ItemStyle.Wrap = False

Thanks,
Princy
0
Stefan
Top achievements
Rank 2
answered on 21 Jun 2013, 01:53 PM
Thank You, this worked.

I have one other question.  I have my columns set to a small font.  But when I click on the edit button it goes back to a normal font and stretches my page.  How can I make the edit textboxes the same as the small font?  As in when the grid is in edit form I want smaller fonts =8  I am creating this columns dynmically.

            With boundColumn
                .DataField = column.ColumnName
                .UniqueName = "dgX" & i
                .Display = True
                .HeaderText = column.ColumnName
                .HeaderStyle.ForeColor = Color.Black
                .HeaderStyle.BackColor = Color.White
                .HeaderStyle.Font.Bold = True
                .ItemStyle.Font.Size = 8
                .ItemStyle.ForeColor = Color.Gray
                .ItemStyle.HorizontalAlign = HorizontalAlign.Left
        end with


Just limiting the textbox size to 6 or so characters would help.  Now the edit text box widths are like 30 characters and thats way to long.
0
Stefan
Top achievements
Rank 2
answered on 21 Jun 2013, 03:03 PM

Thanks I found my answer so I post it here for others:

SUB ItemDataBound-----------------------
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
                Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
                Dim textbox As TextBox = DirectCast(item("YourColumnName").Controls(0), TextBox)

                With textbox
                    .Width = Unit.Percentage(80)
                    .Font.Size = 8
                End With
        End If

Tags
Grid
Asked by
Stefan
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Stefan
Top achievements
Rank 2
Share this question
or