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

Hide a column in Edit mode

6 Answers 1005 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sayle
Top achievements
Rank 1
Sayle asked on 01 Jun 2012, 03:51 PM
I have a need to show a grid will several columns that I don't want the user to see when the grid goes into edit mode.
I am adding the source code to the grid. I need to hide the "Date Due", "Description", "User Reference", etc...
                                <telerik:RadAjaxPanel ID="apnlPayments" runat="server" LoadingPanelID="ajaxLoadingPanel">
                            <telerik:RadGrid ID="gridPayments" runat="server"  AllowAutomaticDeletes="true" AllowAutomaticUpdates="true"
                                AllowAutomaticInserts="true" AllowFilteringByColumn="false" AllowPaging="false" 
                                AllowSorting="true" AllowMultiRowSelection="true" CellSpacing="0" CellPadding="0"
                                PageSize="500" ShowGroupPanel="false" AllowCustomPaging="false" 
                                EnableLinqExpressions="false" GridLines="Both" HeaderStyle-Wrap="false"
                                AutoGenerateColumns="false" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px"
                                OnItemDataBound="grid_ItemDataBound" OnPageIndexChanged="grid_PageIndexChanged"
                                OnPageSizeChanged="grid_PageSizeChanged" OnNeedDataSource="grid_NeedDataSource"
                                OnInsertCommand="gridPayments_InsertCommmand" OnUpdateCommand="gridPayments_UpdateCommand"
                                OnDeleteCommand="gridPayments_DeleteCommand" OnPreRender="gridPayments_PreRender">
                                <ClientSettings allowautoscrollondragdrop="false" allowexpandcollapse="false" allowgroupexpandcollapse="false">
                                    <Selecting AllowRowSelect="true" UseClientSelectColumnOnly="true" />
                                    <Scrolling AllowScroll="false" UseStaticHeaders="true"  FrozenColumnsCount="4" />
                                    <ClientEvents OnGridCreated="grid_GridCreated" />
                                    <Resizing AllowResizeToFit="true" EnableRealTimeResize="true" />
                                </ClientSettings>
                                <MasterTableView EditMode="EditForms" CommandItemDisplay="Top" AutoGenerateColumns="false"
                                    DataKeyNames="LoanPaymentID" InsertItemPageIndexAction="ShowItemOnCurrentPage">
                                    <ItemStyle CssClass="Row0" />
                                    <AlternatingItemStyle CssClass="Row1" />
                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"><HeaderStyle Width="20px" /></RowIndicatorColumn>
                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"><HeaderStyle Width="20px" /></ExpandCollapseColumn>
                                    <Columns>
                                        <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" Visible="true">
                                            <ItemStyle HorizontalAlign="Center" Wrap="false" VerticalAlign="Middle" /></telerik:GridEditCommandColumn>
                                            <telerik:GridButtonColumn ConfirmText="Delete this Payment?" ConfirmDialogType="RadWindow"
                                            ConfirmTitle="Delete" ButtonType="ImageButton" ImageUrl="~/Images/icon_delete.png"
                                            CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                            <ItemStyle HorizontalAlign="Center" />
                                        </telerik:GridButtonColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentPS_ACCT_NO" MaxLength="50" FilterControlAltText="Filter LoanPaymentPS_ACCT_NO column"
                                            HeaderStyle-Wrap="false" HeaderText="PS ACCT NO" SortExpression="LoanPaymentPS_ACCT_NO"
                                            UniqueName="PS_ACCT_NO" ReadOnly="true">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridDateTimeColumn DataField="LoanPaymentDateDue" DataFormatString="{0:MM/dd/yyyy}"
                                            FilterControlAltText="Filter LoanPaymentDateDue column" HeaderStyle-Wrap="false"
                                            HeaderText="DATE DUE" SortExpression="LoanPaymentDateDue" UniqueName="LoanPaymentDateDue" ReadOnly="true">
                                        </telerik:GridDateTimeColumn>
                                        <telerik:GridDateTimeColumn DataField="LoanPaymentDatePaid" DataFormatString="{0:MM/dd/yyyy}"
                                            FilterControlAltText="Filter LoanPaymentDatePaid column" HeaderStyle-Wrap="false"
                                            HeaderText="DATE PAID" SortExpression="LoanPaymentDatePaid" UniqueName="LoanPaymentDatePaid" DataType="System.DateTime">
                                        </telerik:GridDateTimeColumn>
                                        <telerik:GridNumericColumn DataField="LoanPaymentAmount" NumericType="Currency" FilterControlAltText="Filter LoanPaymentAmount column"
                                            HeaderStyle-Wrap="false" HeaderText="AMOUNT" SortExpression="LoanPaymentAmount"
                                            UniqueName="LoanPaymentAmount">
                                        </telerik:GridNumericColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentDescription" MaxLength="50" FilterControlAltText="Filter LoanPaymentDescription column"
                                            HeaderStyle-Wrap="false" HeaderText="DESCRIPTION" SortExpression="LoanPaymentDescription"
                                            UniqueName="LoanPaymentDescription">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentUserReference" MaxLength="50" FilterControlAltText="Filter LoanPaymentUserReference column"
                                            HeaderStyle-Wrap="false" HeaderText="USER REFERENCE" SortExpression="LoanPaymentUserReference"
                                            UniqueName="LoanPaymentUserReference">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentMethodNo" MaxLength="50" FilterControlAltText="Filter LoanPaymentMethodNo column"
                                            HeaderStyle-Wrap="false" HeaderText="METHOD NO" SortExpression="LoanPaymentMethodNo"
                                            UniqueName="LoanPaymentMethodNo">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentMethodReference" MaxLength="50" FilterControlAltText="Filter LoanPaymentMethodReference column"
                                            HeaderStyle-Wrap="false" HeaderText="METHOD REFERENCE" SortExpression="LoanPaymentMethodReference"
                                            UniqueName="LoanPaymentMethodReference">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="LoanPaymentType" MaxLength="50" FilterControlAltText="Filter LoanPaymentType column"
                                            HeaderStyle-Wrap="false" HeaderText="TYPE" SortExpression="LoanPaymentType" UniqueName="LoanPaymentType">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </MasterTableView>
                                <FilterMenu EnableImageSprites="false" />
                                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default" />
                            </telerik:RadGrid>                   
                        </telerik:RadAjaxPanel>

6 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 01 Jun 2012, 04:06 PM
Hi,

Try the following code snippet to make certain row not visible in edit mode.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem eitem = (GridEditableItem)e.Item;
        eitem["UniqueName"].Visible = false;    // for making the cell invisible during editing
        eitem["UniqueName"].Parent.Visible = false; // for making its label also invisible
        
    }
}

Thanks,
Princy.
0
Sayle
Top achievements
Rank 1
answered on 01 Jun 2012, 04:12 PM
Thank You!!!!
0
Pam
Top achievements
Rank 2
answered on 12 Sep 2012, 10:55 PM
How is this in vb.net? thanks
0
Princy
Top achievements
Rank 2
answered on 13 Sep 2012, 03:24 AM

Hi Pam,

Here is the code in VB.

VB:

Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        Dim eitem As GridEditableItem = DirectCast(e.Item, GridEditableItem)
        ' for making the cell invisible during editing
        eitem("UniqueName").Visible = False
         
        ' for making its label also invisible  
        eitem("UniqueName").Parent.Visible = False
    End If
End Sub

Regards,
Princy.

0
Jayesh Goyani
Top achievements
Rank 2
answered on 13 Sep 2012, 06:13 AM
Hello,

for future use you can also convert your code by using below link.

http://converter.telerik.com/

Thanks,
Jayesh Goyani
0
Pam
Top achievements
Rank 2
answered on 14 Sep 2012, 07:28 PM
Hi Jayesh, 

Thank you very much for the link! :)
Tags
Grid
Asked by
Sayle
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sayle
Top achievements
Rank 1
Pam
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or