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

Hide Columns in EditMode, but Show them on Insert

1 Answer 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jamal
Top achievements
Rank 1
Jamal asked on 28 May 2009, 07:52 PM
Greetings,

I'm working with the ASP.NET AJAX RadGrid, and I'm trying to show certain columns when a user is creating a new record, but I want them to be hidden (or read only) when in EditMode. Does anyone have any good examples of this?

Thanks,

Jamal Khan

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 May 2009, 04:14 AM
Hi Jamal,

Try the following code snippet in order to hide the column in Editmode and show in insert mode.

ASPX:
 
<Columns> 
 . . . 
<telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" SortExpression="CustomerID" UniqueName="CustomerID"></telerik:GridBoundColumn> 
 . . . 
</Columns> 

CS:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    foreach (GridColumn col in RadGrid1.Columns) 
    { 
        if (col.ColumnType == "GridBoundColumn" && col.UniqueName == "CustomerID"
        { 
            if (e.CommandName == RadGrid.EditCommandName) 
            { 
                (col as GridBoundColumn).ReadOnly = true
                col.Visible = false
            } 
            else 
            { 
                (col as GridBoundColumn).ReadOnly = false
                col.Visible = true
            } 
        } 
    }    

Thanks,
Shinu.
Tags
Grid
Asked by
Jamal
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or