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

Unable to hide Label in RadGrid in Edit Mode

6 Answers 365 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milan Gurung
Top achievements
Rank 1
Milan Gurung asked on 15 Jan 2010, 04:44 PM
Hi,

Why is it not possible to hide the label during edit mode?
For instance, in the following code, "lblInvoiceDetailID" is not hidden even when visible property is set to false in edit mode....



<telerik:GridTemplateColumn DataField="InvoiceDetailID" HeaderText="InvoiceDetailID" UniqueName="InvoiceDetailID" Display="False">
                        <ItemTemplate>
                            <asp:Label ID="lblInvoiceDetailID" runat="server" Text='<%# Bind("InvoiceDetailID") %>'  Visible="false"> </asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="txtInvoiceDetailID" Text='<%# Bind("InvoiceDetailID") %>'  runat="server" ReadOnly="true" Visible="false"></asp:TextBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>

Any help is highly appreciated.

Many thanks.

Milan G

6 Answers, 1 is accepted

Sort by
0
Accepted
Martin
Telerik team
answered on 18 Jan 2010, 07:54 AM
Hello Milan,

I think that what you actually see is the HeaderText of the column and not the label set in the ItemTemplate. To hide the HeaderText when the column is in edit mode just set EditFormHeaderTextFormat = "". Here is the modified markup:

<telerik:GridTemplateColumn EditFormHeaderTextFormat="" DataField="InvoiceDetailID"
                    HeaderText="InvoiceDetailID" UniqueName="InvoiceDetailID">
                    <ItemTemplate>
                        <asp:Label ID="lblInvoiceDetailID" runat="server" Text='<%# Bind("InvoiceDetailID") %>'> </asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtInvoiceDetailID" Text='<%# Bind("InvoiceDetailID") %>' runat="server"></asp:TextBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>


I hope this helps.
Martin
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Milan Gurung
Top achievements
Rank 1
answered on 18 Jan 2010, 09:25 AM
Thank you very much Martin!
0
Samir
Top achievements
Rank 1
answered on 01 Apr 2014, 02:51 PM
Hi,

Is there a possibility to change EditFormHeaderTextFormat value (column label in Edit/Insert) based on the value of a combo box in radgrid? OnSelectIndexChanged.
0
Princy
Top achievements
Rank 2
answered on 02 Apr 2014, 03:35 AM
Hi Samir,

I guess you want to set the EditFormHeaderTextFormat of a template column, when the value in RadComboBox in EditItemTemplate is selected. Please try the following code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerID">
    <ItemTemplate>
        <%#Eval("CustomerID") %>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource2" AutoPostBack="true" DataTextField="CustomerID" DataValueField="CustomerID" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
  RadComboBox combo = (RadComboBox)sender;
  string value = combo.SelectedItem.Text;
  RadGrid1.MasterTableView.GetColumn("CustomerID").EditFormHeaderTextFormat = value;   
  RadGrid1.Rebind();     
}

Thanks,
Princy
0
Samir
Top achievements
Rank 1
answered on 02 Apr 2014, 09:21 AM
Thanks Princy,
This part works but it's not exactly my scenario. I need combo in one column to change the title and hide textbox (EditItemTemplate) in the second column (GridTemplateColumn), depend on combo selectedvalue. Another problem is that RadGrid1.Rebind(); reset SelectedValue in the combo.
0
Princy
Top achievements
Rank 2
answered on 03 Apr 2014, 03:38 AM
Hi Samir,

Please try the following sample code snippet to change the EditFormHeaderTextFormat of a column and hide its TextBox.

ASPX:
<telerik:GridTemplateColumn HeaderText="CustomerID" UniqueName="CustomerID">
    <ItemTemplate>
        <%#Eval("CustomerID") %>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource2"
            AutoPostBack="true" DataTextField="CustomerID" DataValueField="CustomerID" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
        </telerik:RadComboBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="ShipCity" UniqueName="ShipCity">
    <ItemTemplate>
        <%#Eval("ShipCity")%>
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

C#:
string value = string.Empty;
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        RadComboBox combo = (RadComboBox)edit.FindControl("RadComboBox1");
        if (value != string.Empty)
        {
            //Hide the TextBox and store the value in ComboBox
            TextBox txt = (TextBox)edit.FindControl("TextBox1");
            txt.Visible = false;
            combo.SelectedValue = value;
        }
        else
            combo.SelectedValue = DataBinder.Eval(edit.DataItem, "CustomerID").ToString();       
    }
}
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox combo = (RadComboBox)sender;
    GridEditableItem edit = (GridEditableItem)combo.NamingContainer;
    value = combo.SelectedItem.Text; 
    RadGrid1.MasterTableView.GetColumn("ShipCity").EditFormHeaderTextFormat = value;   
    RadGrid1.Rebind();  
    combo.SelectedItem.Text = value;
}

Thanks,
Princy
Tags
Grid
Asked by
Milan Gurung
Top achievements
Rank 1
Answers by
Martin
Telerik team
Milan Gurung
Top achievements
Rank 1
Samir
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or