GridTemplateColumn Hiding

4 posts, 0 answers
  1. YKP
    YKP avatar
    4 posts
    Member since:
    Feb 2011

    Posted 15 Oct 2012 Link to this post

    Hello, 

    Quite accidentally, I've found an interesting behavior with the RadGrid's GridTemplateColumn:

    <telerik:RadGrid runat="server" ID="radgrid" AutoGenerateColumns="false" OnNeedDataSource="radgrid_NeedDataSource">
        <MasterTableView>
            <Columns>
                <telerik:GridTemplateColumn DataField="Text" HeaderText="foo">
                    <ItemTemplate>
                        <%# Eval("Text") %>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="Text" HeaderText="bar" Visible="false" />
                <telerik:GridEditCommandColumn HeaderText="Edit" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    In normal mode, the GridTemplateColumn will be visible, but when in edit mode, it's the GridBoundColumn that's visible. You can tell by the HeaderText that's displayed in the edit form.

    Out of curiosity, is this an intended behavior?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 15 Oct 2012 Link to this post

    Hi,

    • ItemTemplate is the template that appears in column cells in browser mode.

    • EditItemTemplate is the template that appears in column cells in edit mode.

      You can provide custom controls in the column which are needed in edit mode. Check the following help documentation which explains more about this.
      Column Types

      Thanks,
      Shinu.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. YKP
    YKP avatar
    4 posts
    Member since:
    Feb 2011

    Posted 16 Oct 2012 Link to this post

    Hi,

    Thanks, but I already know all that. I admit my first bit of code might have been misleading because of the template column, so check this one instead:

    <telerik:RadGrid runat="server" ID="radgrid" AutoGenerateColumns="false" OnNeedDataSource="radgrid_NeedDataSource">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="Text" HeaderText="bar" Visible="false" />
                <telerik:GridEditCommandColumn HeaderText="Edit" />
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    Note that the GridBoundColumn is set to Visible="False". In normal mode, this code will only show the GridEditCommandColumn. However, in edit mode, it will show a label + textbox for the GridBoundColumn, even though it's set to Visible="False".

    Now, unless I'm wrong, shouldn't it simply show nothing when in edit mode?

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Oct 2012 Link to this post

    Hi,

    In order to hide the column in edit mode you should set  ReadOnly property as true instead of Visible property.
    aspx:
    <telerik:GridBoundColumn  ReadOnly="true" DataField="Text" HeaderText="bar" />
    Also you can hide the column in edit mode as shown below.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
     if (e.Item is GridEditableItem && e.Item.IsInEditMode )
     {
       GridEditableItem item = (GridEditableItem)e.Item;
       TextBox txtbox = (TextBox)item["Text"].Controls[0] as TextBox;
       txtbox.Visible = false;
     }
    }

    Thanks,
    Shinu.
Back to Top