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

Hide Gridbounddata column?

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 2
Stefan asked on 03 Jul 2013, 09:40 PM
Hi,

I have a radgrid with 4 columns 2 of the columns are part of a key.  My problem is I don't want these columns to show but I still need access to their contents.

Setting the visible property to false doesnt show the column but I the cell value is nothing
Setting the display works but now when I add a new record or in edit mode the fields are editable which I don't want because they are a part of the key.

So how can:

1. Make the column not show
2. Make the columns contents accessible with codebehind
3. Make the column not editable during a batch edit
4. Make the column not display an editbox while doing an Add New

I have tried just about every combination, even with GridColumVisibleMode.AlwaysHidden

This is the Column I want to hide, but have access to but not show in edit mode or show when I do Add New.

            Dim boundColumn As GridBoundColumn

            boundColumn = New GridBoundColumn()
            dgCompNonGrid.MasterTableView.Columns.Add(boundColumn)
            boundColumn.DataField = "ippComponentID"
            boundColumn.UniqueName = "dgippComponentID"
            'boundColumn.Display = False
            boundColumn.HeaderText = ""
            boundColumn.ItemStyle.Font.Size = 8
            boundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Left
            boundColumn.ReadOnly = True
            boundColumn.Visible = False
            'boundColumn.InsertVisiblityMode = GridColumnVisibilityMode.AlwaysHidden


Please, thank you.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Jul 2013, 06:43 AM
Hi Stefan,

I have tried to replicate the issue,but no avail.I have used the display property to hide the column and access it later.
Please have a look at the code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"   onitemcommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="CustomerID">           
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub Page_Init(sender As Object, e As System.EventArgs)
    If Not IsPostBack Then
        DefineGridStructure()
    End If
End Sub
Private Sub DefineGridStructure()
    Dim boundColumn As New GridBoundColumn()
    RadGrid1.MasterTableView.Columns.Add(boundColumn)
    boundColumn.DataField = "CustomerID"
    boundColumn.HeaderText = "Customer ID"
    boundColumn.UniqueName = "CustomerID"
    boundColumn.Display = False
 
    Dim boundColumn1 As New GridBoundColumn()
    RadGrid1.MasterTableView.Columns.Add(boundColumn1)
    boundColumn1.DataField = "ContactName"
    boundColumn1.HeaderText = "Contact Name"
 
    Dim buttoncolumn As New GridButtonColumn()
    RadGrid1.MasterTableView.Columns.Add(buttoncolumn)
    buttoncolumn.Text = "ID"
    buttoncolumn.HeaderText = "ID"
    buttoncolumn.CommandName = "Click"
End Sub
 
 
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs)
    If e.CommandName = "Click" Then
        Response.Write("CustomerID: " + TryCast(e.Item, GridDataItem).GetDataKeyValue("CustomerID").ToString() + "<br>")
    End If
End Sub

Thanks,
Shinu
0
Stefan
Top achievements
Rank 2
answered on 10 Jul 2013, 01:55 PM
Correct setting the display to false does not show the value and I can access the value in code.  Proplem is when I do an Add New or Edit the fields DO show and I do not want them to show because they are part of a key and the user should not be able to add these 2 fields or edit them and setting the display = false WILL show these fields on an ADD NEW or EDIT.

What I need is for the column to:

1. Not show while the grid is visible.
2. Be accessible through code behind.
3. Not show in EDIT MODE
4. Not show during and ADD NEW

Is this possible in vb code behind, advanced databinding, program column creation.

This is what happens when I:

            boundColumn = New GridBoundColumn()
            dgCompNonGrid.MasterTableView.Columns.Add(boundColumn)
            boundColumn.DataField = "ippComponentSeq"
            boundColumn.UniqueName = "dgippComponentSeq"
            boundColumn.HeaderText = ""
            boundColumn.ItemStyle.Font.Size = 8
            boundColumn.Display = False
            boundColumn.ReadOnly = True

See attached SS how it moves the columns over during and Add New???

Thanks I been dealing with this for days and can not find the correct combination to make it possible.




0
Princy
Top achievements
Rank 2
answered on 11 Jul 2013, 04:53 AM
Hi Stefan,

I tried to replicate the issue but no avail.If you don't want to see a column you can set it's Display=false,and that will be accessible, and when you don't want to edit or add to that column you can set ReadOnly=true.Here is the code snippet i tried it works fine on my side.
I have attached a screenshot of what i obtained, only one column to insert is shown.

VB:
Protected Sub Page_Init(sender As Object, e As System.EventArgs)
    If Not IsPostBack Then
        DefineGridStructure()
    End If
End Sub
Private Sub DefineGridStructure()
    Dim boundColumn As New GridBoundColumn()
    boundColumn = New GridBoundColumn()
    RadGrid1.MasterTableView.Columns.Add(boundColumn)
    boundColumn.DataField = "CustomerID"
    boundColumn.UniqueName = "CustomerID"
    boundColumn.HeaderText = "CustomerID"
    boundColumn.ItemStyle.Font.Size = 8
    boundColumn.Display = False
    boundColumn.[ReadOnly] = True
 
    Dim boundColumn1 As New GridBoundColumn()
    RadGrid1.MasterTableView.Columns.Add(boundColumn1)
    boundColumn1.DataField = "ContactName"
    boundColumn1.HeaderText = "Contact Name"
   
End Sub

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