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

Visible Labels Rad Grid

2 Answers 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
william
Top achievements
Rank 1
william asked on 10 Nov 2010, 09:00 PM
Good day,

I have an issue, I'm trying to hide a pair of labels in the grid binding process however the following code doesn't work
//item is about to select
       if ((e.Item is GridDataItem && !(!(e.Item is GridEditFormInsertItem) && e.Item.IsInEditMode)) && !((e.Item.OwnerTableView.IsItemInserted && e.Item is GridEditFormInsertItem)))
       {
           GridDataItem item = (GridDataItem)e.Item;
           Label label = (Label)item["Encargado2"].FindControl("LabelEncargado2");
           label.Visible = false;
           Label label2 = (Label)item["Email2"].FindControl("Email2");
           label2.Visible = false;
           label.Parent.Parent.Visible = false;<- This is my problem (it doesn't work!!)
           label2.Parent.Parent.Visible = false;
 
       }

And the code behind: 
<telerik:GridTemplateColumn  UniqueName="Encargado2" DataField="Encargado2" HeaderText="Encargado2"
          ForceExtractValue="InEditMode" ConvertEmptyStringToNull="true" >  
                 <ItemTemplate>
                 <asp:Label ID="LabelEncargado2" runat="server" Text='<%#Eval("Encargado2") %>'></asp:Label>
             </ItemTemplate>
         </telerik:GridTemplateColumn>  
    
      <telerik:GridTemplateColumn  UniqueName="Email2" DataField="Email2" HeaderText="Email2"
          ForceExtractValue="InEditMode" ConvertEmptyStringToNull="true" >  
                 <ItemTemplate>
                 <asp:Label ID="Email2" runat="server" Text='<%#Eval("Email2") %>' Visible="false"></asp:Label>
             </ItemTemplate>
         </telerik:GridTemplateColumn

I pretend both edit them in the GridEditFormItem event and insert them in the GridEditFormInsertItem event however I don't need to display them when I'm loading the grid the first time.
Any suggestion??
Thanks in advance!!
All the Best,
William

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Nov 2010, 05:34 AM
Hello William,

I guess you want to hide the Label with header text inside GridTemplateColumn. If so you can hide the column in PreRender event like below.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        (RadGrid1.MasterTableView.GetColumn("Encargado2") as GridTemplateColumn).Visible = false;
        (RadGrid1.MasterTableView.GetColumn("Email2") as GridTemplateColumn).Visible = false;
    }

Thanks,
Princy.
0
william
Top achievements
Rank 1
answered on 13 Nov 2010, 03:50 PM
it works Thanks
Tags
Grid
Asked by
william
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
william
Top achievements
Rank 1
Share this question
or