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

Show/Hide GridTemplateColumn

4 Answers 463 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan Hughes
Top achievements
Rank 1
Bryan Hughes asked on 01 Jan 2014, 12:24 AM
Hello,
I have a grid with many columns.  Two columns are GridTemplateColumns.  One Column has a RadComboBox and the other has a textbox.

How can I hide GridTemplateColumn with textbox on Insert and then show column when a value like  "Other" is selected from RadComboBox?  I would need same functionality when in Edit Mode.

Thank You Bryan

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 02 Jan 2014, 04:44 AM
Hi Bryan Hughes,

Please have a look into the below sample code snippet
to achieve your required scenario:

ASPX:
<telerik:GridTemplateColumn>
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Visible="false"></asp:TextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
    <EditItemTemplate>
        <telerik:RadComboBox ID="RadComboBox" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox_SelectedIndexChanged">
            <Items>
                <telerik:RadComboBoxItem Text="SomeValue" Value="SomeValue" />
                <telerik:RadComboBoxItem Text="Other" Value="Other" />
            </Items>
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridEditableItem edit = (GridEditableItem)combo.NamingContainer;
    TextBox txt = (TextBox)edit.FindControl("TextBox1");
    if (combo.SelectedValue == "Other")
    {
        txt.Visible = true;
    }
    else
    {
        txt.Visible = false;
    }
}

Thanks,
Princy
0
Bryan Hughes
Top achievements
Rank 1
answered on 07 Jan 2014, 10:29 PM
Thanks for the help.

This works for the text box, but does not hide the column label text.  How can I also show hide column label text?
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Jan 2014, 03:45 AM
Hi Bryan Hughes,

Please try the following code snippet to hide the label text during edit:

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem item = (GridEditableItem)e.Item;
        TextBox txtBox = (TextBox)item.FindControl("TextBox1");
        txtBox.Parent.Parent.Visible = false;
    }
}
protected void RadComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridEditableItem edit = (GridEditableItem)combo.NamingContainer;
    TextBox txt = (TextBox)edit.FindControl("TextBox1");
    if (combo.SelectedValue == "Other")
    {
        txt.Parent.Parent.Visible = true;
        txt.Visible = true;
    }
    else
    {
        txt.Parent.Parent.Visible = false;
        txt.Visible = false;
    }
}

Thanks,
Princy
0
Bryan Hughes
Top achievements
Rank 1
answered on 08 Jan 2014, 09:57 PM
Thank you that is exactly what I needed.

Bryan
Tags
Grid
Asked by
Bryan Hughes
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Bryan Hughes
Top achievements
Rank 1
Share this question
or