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

problem with visibility of column in grid dynamic creation

3 Answers 315 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Veena
Top achievements
Rank 1
Veena asked on 20 Jun 2013, 06:23 AM
Hi there,
I am creating a radgrid dynamically in page load. i have added autogenerated delete column as guided by Princy and is working great. my new issue with that grid is that i am adding two more columns to that radgrid as below(in page load itself).  
Dim updateColumn As New GridButtonColumn()
    radGdItems.MasterTableView.Columns.Add(updateColumn)
            updateColumn.CommandName = "Update"
            updateColumn.Text = "Update"
            updateColumn.UniqueName = "Update"
            updateColumn.Visible = False

boundColumn = New GridBoundColumn()
        radGdItems.MasterTableView.Columns.Add(boundColumn)
        boundColumn.UniqueName = "WarningIcon"
        boundColumn.ItemStyle.Width = Unit.Pixel(25)
        boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center
also adding detail table like this
Dim tableViewWarnings As New GridTableView(radGdItems)
            tableViewWarnings.Name = "DetalTable1"
            radGdItems.MasterTableView.DetailTables.Add(tableViewWarnings)
            boundColumn = New GridBoundColumn()
            tableViewWarnings.Columns.Add(boundColumn)
            boundColumn.DataField = "Warning"
and am managing the visibility of these three items in prerender as follows

For Each dataItem As GridDataItem In radGdItems.MasterTableView.Items
                    If condition = true Then
                        radGdItems.AllowMultiRowSelection = True
                        radGdItems.Columns.FindByUniqueName("Update").Visible = True
                        dataItem.Selected = True

                        ExpandColumnVisible = True
                        dataItem("WarningIcon").Visible = True
                        dataItem.Item("WarningIcon").Text = "<img src=""../Images/Warning.gif"" />"
                    Else
                        dataItem("Update").Text = "&nbsp;"
                        Dim cell As TableCell = dataItem.Item("ExpandColumn")
                        cell.Controls().Clear()
                        dataItem("WarningIcon").Text = "&nbsp;"
                    End If
                Next

I mean, these columns (the warning icon column and expand collapse column) are visible based on a condition. 
this grid is in one radtab inside a usercontrol and i have another radtab containing a grid in the parent page. An update in the parent page grid row can set the condition for the column visibility to true. 

Suppose,initially the update column, warningIcon column and detail table is not visible for the rows in the dynamically created grid, and when i update a row in the parent page, the condition is set to true,and this entire code works(i mean control flows through this code) setting those columns visible = true. but the initially hidden columns does not become visible. instead the dataItem.Selected = True line only works. that means, the rows, where actually these columns need to be visible become selected, but columns not visible.

i have applied ajax in the parent page grid as
<telerik:AjaxSetting AjaxControlID="radGdVM">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="radGdVM"  LoadingPanelID="RadAjaxLoadingPanel1" />
                    <telerik:AjaxUpdatedControl ControlID="UserControl1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
if i do a complete postback in the page, the columns become visible.
what is wrong with my code and what i need to do to make the columns visible?

Expecting some good advice,

Regards

Veena

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 25 Jun 2013, 05:37 AM
Hi,

Most probably the problem comes from the fact that you are not invoking the Rebind() method of RadGrid. Try to call the Rebind method after you set the property values in the PreRender event and you should not have problems:

For Each dataItem As GridDataItem In radGdItems.MasterTableView.Items
    If condition = true Then
        radGdItems.AllowMultiRowSelection = True
        radGdItems.Columns.FindByUniqueName("Update").Visible = True
        dataItem.Selected = True
 
        ExpandColumnVisible = True
        dataItem("WarningIcon").Visible = True
        dataItem.Item("WarningIcon").Text = "<img src=""../Images/Warning.gif"" />"
    Else
        dataItem("Update").Text = " "
        Dim cell As TableCell = dataItem.Item("ExpandColumn")
        cell.Controls().Clear()
        dataItem("WarningIcon").Text = " "
    End If
Next
radGdItems.Rebind()

Regards,
Andrey
Telerik
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 the blog feed now.
0
Veena
Top achievements
Rank 1
answered on 25 Jun 2013, 06:33 AM
Hi Andrey,

Thanks for the reply. But that solution didn't work for me.
Now, the expand image is visible for all rows even if it has no child row. also the warning image column has 'System.Data.DataRowView' for every row disregarding the child row. I hope u understood me and can help me further.

Thanks,
Veena
0
Andrey
Telerik team
answered on 27 Jun 2013, 12:30 PM
Hi,

Please share your full page source code along with the code-behind file content. Thus all the people who want to help you will have better understanding of your case.

Regards,
Andrey
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Veena
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Veena
Top achievements
Rank 1
Share this question
or