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

GridButton Column disappears

2 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chuck Harrington
Top achievements
Rank 1
Chuck Harrington asked on 23 Mar 2011, 09:04 PM

Ok.  This is driving me nuts, because I'm missing what's causing this to happen.  I am creating RadGrid columns programmatically, using one grid (aspx page) for 7 different datasources, controlled by a Case statement.  My problem is that if I click either on the Edit button( GridEditCommandColumn) or on the Delete button (GridButtonColumn), the Delete button disappears on postback.  All other columns(GridBoundColumn) reappear just fine.  Here is the snippet of code. It appears in a Page Load event.  The DataSourceID is supplied with a NeedDataSource event which is why it is commented out in the snippet.  What am I missing?  Thanks in advance.

If Not IsPostBack Then
            Dim intReport As Integer = Request("Report")
            Select intReport
                Case 0
                    ' Comments
                    'rgDisplay.DataSourceID = "CommentsDS"
                    rgDisplay.MasterTableView.DataKeyNames = New String() {"CMT_REC_ID"}
                    rgDisplay.Width = Unit.Percentage(90)
                    rgDisplay.PageSize = 5
                    rgDisplay.AllowPaging = True
                    rgDisplay.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
                    rgDisplay.AutoGenerateColumns = False
                    rgDisplay.Skin = "Hay"
                    rgDisplay.MasterTableView.PageSize = 20
                    rgDisplay.MasterTableView.Width = Unit.Percentage(100)
                    rgDisplay.MasterTableView.EditMode = GridEditMode.InPlace
                    Dim colEdit As GridEditCommandColumn
                    colEdit = New GridEditCommandColumn
                    colEdit.UniqueName = "EditCommandColumn"
                    colEdit.ItemStyle.Width = Unit.Pixel(25)
                    rgDisplay.MasterTableView.Columns.Add(colEdit)
                    Dim colDel As GridButtonColumn
                    colDel = New GridButtonColumn
                    colDel.Visible = True
                    colDel.CommandName = "Delete"
                    colDel.UniqueName = "cmdDelete"
                    colDel.Text = "Delete"
                    colDel.ItemStyle.Width = Unit.Pixel(25)
                    rgDisplay.MasterTableView.Columns.Add(colDel)
                    Dim colBound As GridBoundColumn
                    colBound = New GridBoundColumn
                    rgDisplay.MasterTableView.Columns.Add(colBound)
                    colBound.DataField = "CMT_REC_ID"
                    colBound.HeaderText = "Number"
                    colBound.UniqueName = "CMTRecID"
                    colBound = New GridBoundColumn
                    rgDisplay.MasterTableView.Columns.Add(colBound)
                    colBound.DataField = "CMT_DESCRIPTION"
                    colBound.HeaderText = "Description"
                    colBound.UniqueName = "CMTDescription"

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Mar 2011, 06:06 AM
Hello Chuck,

You should add columns to the corresponding collection first, before the values for their properties are set like below.

Vb.Net:
Dim colDel As GridButtonColumn = Nothing
colDel = New GridButtonColumn()
rgDisplay.MasterTableView.Columns.Add(colDel)
colDel.Visible = True
colDel.CommandName = "Delete"
colDel.UniqueName = "cmdDelete"
colDel.Text = "Delete"
colDel.ItemStyle.Width = Unit.Pixel(25)

Also refer this documentation.
Programmatic creation

Thanks,
Princy.
0
Chuck Harrington
Top achievements
Rank 1
answered on 24 Mar 2011, 03:21 PM
As Homer Simpson would say "D-Oh".  Thanks Princy.  Works like it is supposed to.  Sometimes can't see forest for the trees!
Tags
Grid
Asked by
Chuck Harrington
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Chuck Harrington
Top achievements
Rank 1
Share this question
or