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

Hiding columns in edit mode

5 Answers 274 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vjeran
Top achievements
Rank 2
Vjeran asked on 03 Mar 2009, 12:39 PM
Hi,
i have situation where i need to update only certan columns in database. I to this in normal mode like:
private void HideGridColumnsByType(RadGrid grid)
        {
            GridColumn column;
            switch (ReturnSelectedType())
            {
                case DbType.Int32:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierIntValue");
                    column.Visible = true;
                    break;
                case DbType.Single:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDecimalValue");
                    column.Visible = true;
                    break;
                case DbType.DateTime:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDateTimeValue");
                    column.Visible = true;
                    break;
                case DbType.String:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierStringValue");
                    column.Visible = true;
                    break;
                case DbType.Boolean:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierBooleanValue");
                    column.Visible = true;
                    break;
            }
        }
And this works fine. Still, when i am under event for edit
 if (e.CommandName == "Edit")
                {
                    var edititem = e.Item as GridEditableItem;
                    //edititem["ModifierIntValue"].Visible = false;
                    //edititem["ModifierDecimalValue"].Visible = false;
                    //edititem["ModifierDateTimeValue"].Visible = false;
                    //edititem["ModifierStringValue"].Visible = false;
                    //edititem["ModifierBooleanValue"].Visible = false;
                    edititem.EditManager.GetColumnEditor("ModifierIntValue").ContainerControl.Visible = false;
                    edititem.EditManager.GetColumnEditor("ModifierDecimalValue").ContainerControl.Visible = false;
                    edititem.EditManager.GetColumnEditor("ModifierDateTimeValue").ContainerControl.Visible = false;
                    edititem.EditManager.GetColumnEditor("ModifierStringValue").ContainerControl.Visible = false;
                    edititem.EditManager.GetColumnEditor("ModifierBooleanValue").ContainerControl.Visible = false;
                    switch (ReturnSelectedType())
                    {
                        case DbType.Int32:
                            edititem.EditManager.GetColumnEditor("ModifierIntValue").ContainerControl.Visible = true;
                            //column = grid.MasterTableView.Columns.FindByUniqueName("ModifierIntValue");
                            //column.Visible = true;
                            break;
                        case DbType.Single:
                            edititem.EditManager.GetColumnEditor("ModifierDecimalValue").ContainerControl.Visible = false;
                            //column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDecimalValue");
                            //column.Visible = true;
                            break;
                        case DbType.DateTime:
                            edititem.EditManager.GetColumnEditor("ModifierDateTimeValue").ContainerControl.Visible = false;
                            //column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDateTimeValue");
                            //column.Visible = true;
                            break;
                        case DbType.String:
                            edititem.EditManager.GetColumnEditor("ModifierStringValue").ContainerControl.Visible = false;
                            //column = grid.MasterTableView.Columns.FindByUniqueName("ModifierStringValue");
                            //column.Visible = true;
                            break;
                        case DbType.Boolean:
                            edititem.EditManager.GetColumnEditor("ModifierBooleanValue").ContainerControl.Visible = false;
                            //column = grid.MasterTableView.Columns.FindByUniqueName("ModifierBooleanValue");
                            //column.Visible = true;
                            break;
                    }
                }

this doesn't work? anyone has an idea how to hide fields when i press edit?

Thanks,
Vjeran






5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Mar 2009, 12:51 PM
Hi Vjeran,

Have you tried setting the ReadOnly property for the desired Grid column? If not just give a try with the ReadOnly property which will prevent editing of the Grid column when set to true.

Shinu
0
Vjeran
Top achievements
Rank 2
answered on 03 Mar 2009, 01:24 PM
Is there no way to hide them or that will cause errors? well readonly could work but i would rather hide them completely.
I don't understand why i can't hide them? or am i doing something wrong? it works fine in first case.

0
Vjeran
Top achievements
Rank 2
answered on 03 Mar 2009, 05:33 PM
       private void HideGridColumnsByType(RadGrid grid)
        {
            GridColumn column;

            switch (ReturnSelectedType())
            {
                case DbType.Int32:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierIntValue");
                    ((GridBoundColumn)grid.MasterTableView.GetColumnSafe("ModifierIntValue")).ReadOnly = false;
                    column.Display = true;
                    break;
                case DbType.Single:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDecimalValue");
                    ((GridBoundColumn)grid.MasterTableView.GetColumnSafe("ModifierDecimalValue")).ReadOnly = false;
                    column.Display = true;
                    break;
                case DbType.DateTime:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierDateTimeValue");
                    ((GridBoundColumn)grid.MasterTableView.GetColumnSafe("ModifierDateTimeValue")).ReadOnly = false;
                    column.Display = true;
                    break;
                case DbType.String:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierStringValue");
                    ((GridBoundColumn)grid.MasterTableView.GetColumnSafe("ModifierStringValue")).ReadOnly = false;
                    column.Display = true;
                    break;
                case DbType.Boolean:
                    column = grid.MasterTableView.Columns.FindByUniqueName("ModifierBooleanValue");
                    ((GridCheckBoxColumn)grid.MasterTableView.GetColumnSafe("ModifierBooleanValue")).ReadOnly = false;
                    column.Display = true;
                    break;
            }
        }
Well now i placed this as prerender. But this seems to break on edit event and my grid even doesn't open in edit mode. in debugger i don't get any error and it does break before it enters into this method.
0
Vjeran
Top achievements
Rank 2
answered on 03 Mar 2009, 06:01 PM
                    <telerik:RadGrid ID="ModifierKeyValuePairs" runat="server" Skin="Outlook" AutoGenerateColumns="False"
                        AllowPaging="True" AllowAutomaticDeletes="True" AllowCustomPaging="False" AutoGenerateDeleteColumn="True"
                        GridLines="None" PageSize="15" ClientSettings-Selecting-AllowRowSelect="true" DataSourceID="ModifierKeyValuesDs"
                        AllowSorting="false" AllowAutomaticInserts="false" AutoGenerateEditColumn="true" Width="100%"
                        OnItemCommand="KeyValuePairItemCommand" OnPreRender="ModifiersKeyValuesDataBound">
                        <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
                        <MasterTableView DataKeyNames="Id" ShowHeadersWhenNoRecords="False">
                            <NoRecordsTemplate>
                                <table style="width: 100%;" class="rh25px">
                                    <tbody class="bluegridlines">
                                        <tr>
                                            <td colspan="2">
                                                <div style="padding-top: 10px; padding-bottom: 10px;">
                                                    No records.
                                                </div>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </NoRecordsTemplate>
                            <Columns>
                                <telerik:GridBoundColumn DataField="ModifierKey" HeaderText="Key" ReadOnly="False" HeaderStyle-ForeColor="White"
                                    SortExpression="ModifierKey" UniqueName="ModifierKey" ItemStyle-Width="300" HeaderStyle-Width="400"
                                    FooterStyle-Width="300">
                                </telerik:GridBoundColumn>
                                <telerik:GridNumericColumn DataField="ModifierIntValue" UniqueName="ModifierIntValue"
                                HeaderText="Value" DataType="System.Int32" Display="false" ReadOnly="true"></telerik:GridNumericColumn>
                                <telerik:GridNumericColumn DataField="ModifierDecimalValue" UniqueName="ModifierDecimalValue"
                                HeaderText="Value" DataType="System.Single" Display="false" ReadOnly="true"></telerik:GridNumericColumn>
                                <telerik:GridDateTimeColumn DataField="ModifierDateTimeValue" UniqueName="ModifierDateTimeValue"
                                HeaderText="Value" DataType="System.DateTime" Display="false" ReadOnly="true"></telerik:GridDateTimeColumn>
                                <telerik:GridBoundColumn DataField="ModifierStringValue" UniqueName="ModifierStringValue"
                                HeaderText="Value" Display="false" ReadOnly="true"></telerik:GridBoundColumn>
                                <telerik:GridCheckBoxColumn DataField="ModifierBooleanValue" UniqueName="ModifierBooleanValue"
                                HeaderText="Value" Display="false" ReadOnly="true"></telerik:GridCheckBoxColumn>                          
                                <telerik:GridTemplateColumn ReadOnly="true">
                                    <ItemTemplate>
                                        <asp:ImageButton ID="UpButton" runat="server" ImageUrl="~/App_Themes/Backend/images/order-up.gif" style="margin:1px;" />
                                        <asp:ImageButton ID="DownButton" runat="server" ImageUrl="~/App_Themes/Backend/images/order-down.gif" style="margin:1px;" />
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                            <ItemStyle Height="25" />
                            <AlternatingItemStyle Height="25" />
                        </MasterTableView>
                    </telerik:RadGrid>
This is my aspx code.
And i added grid.Rebind() to method above. everything is same as on http://www.telerik.com/help/aspnet/grid/grdusingcolumns.html
but still my edit item form doesn't want to open.
0
Vjeran
Top achievements
Rank 2
answered on 04 Mar 2009, 05:56 PM
Hi,
well, i'm not sure why above is not working .. well, i went to use that entity object datasource but more that i use telerik more i think that i should really stick to sqldatasource and to get only things that i need and to forget update by using store procedures and nettiers.

My problem wouldn't exist if i was using sqldatasource so - in case there are people who have same problem - i would suggest to think not to hide-show columns. rather to make simple custom sql query and that's it!

Tags
Grid
Asked by
Vjeran
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Vjeran
Top achievements
Rank 2
Share this question
or