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

Change legend dynamically

2 Answers 208 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Cristian
Top achievements
Rank 1
Cristian asked on 28 Jan 2013, 08:09 PM
Hi guys I'm working with RadListView as the main menu of my application, and I'm facing the next problem.
As you can see, I have two legends(one commented), my question is how can I change the legend dynamically
based on an integer parameter loaded on page_load event.




<
telerik:RadListView  Width="600px"
                     ID="RadListView1" runat="server"
                            ItemPlaceholderID="ProductsHolder"
                            onselectedindexchanged="RadListView1_SelectedIndexChanged"
                            onneeddatasource="RadListView1_NeedDataSource1"  PageSize="2
                            " AllowPaging="true"  DataKeyNames="fiIdReforma" Skin="Black" >
 
                     <LayoutTemplate>
 
                        <table>
                                 <tr> <td>
                           
                         <h3 style="color: #FFFFFF; font-weight: bold;" >DASHBOARDS</h3>
                     
                        </td></tr>
                        <tr>
 
                        <td>
                         <fieldset style="width: 900px;"  >
 
             <%--       <legend style="color: #FFFFFF">REFORMAS</legend>--%>
                     
                    <legend style="color: #FFFFFF">OBRAS PÚBLICAS</legend>
                    <asp:Panel ID="ProductsHolder" runat="server" />
 
                </fieldset>
                        </td>
 
                        </table>
 
                        <asp:ImageButton runat="server" ID="btnPrev" CommandName="Page" CommandArgument="Prev"
 
Text="Anterior"  Visible="<%#Container.CurrentPageIndex > 0 %>"  ImageUrl="~/img/black_left2.png"    />
 
                                                                                                                                                <asp:ImageButton runat="server" ID="btnNext" CommandName="Page" CommandArgument="Next"
Text="Siguiente" Visible="<%#Container.CurrentPageIndex + 1 < Container.PageCount %>"  ImageUrl="~/img/black_right2.png" />
            </LayoutTemplate>
 
            <ItemTemplate>
 
                <div class="reforma">
 <%--  <span>
    <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("fcDescRef") %>'   Font-Bold="true" ClientIDMode="Inherit" ForeColor="White" />
   </span>--%>
   <br />
  <table>
  <tr>
  <td>
  <span>
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("fcDescRef") %>'  Width="200px"  Font-Bold="true"   ClientIDMode="Inherit"  ForeColor="White" style="text-align:justify; vertical-align:middle;" />
   </span>
  </td>
  <td><span>
    <asp:ImageButton ID="SushiImage" runat="server" AlternateText='<%# Eval("fcDescRef") %>' Width="150px" CommandName="Select" ImageUrl='<%# Eval("fcURLimg") %>' />
   </span></td>
  </tr>
  
  </table>
    
 
    
                <%--<table>
                <tr>
                <td>
 
                 <asp:Label ID="AddressLabel" runat="server" Text='<%# Eval("fcDescRef") %>'   Font-Bold="true" ClientIDMode="Inherit" ForeColor="White" />
                </td>
                </tr>
                <tr>
                <td>
 
                <asp:ImageButton ID="SushiImage" runat="server" AlternateText='<%# Eval("fcDescRef") %>' Width="150px" CommandName="Select" ImageUrl='<%# Eval("fcURLimg") %>' />
 
                </td>
 
                <td align="left">
                   <asp:Label ID="Label1" runat="server" Text='<%# Eval("fcObs") %>'  Width="200px"  Font-Bold="true"  ClientIDMode="Inherit"  ForeColor="White" />
                </td>
                </tr>
                </table>--%>
                </div>
 
            </ItemTemplate>
 
                 </telerik:RadListView>

Hope Your Help.

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 29 Jan 2013, 10:57 AM
Hi Cristian

Try the following code snippet to access the legend in the LayoutTemplate of RadListView.
aspx:
<legend id="test" runat="server" style="color: #FFFFFF">OBRAS PÚBLICAS</legend>
C#:
protected void Page_Load(object sender, EventArgs e)
{
    if(condition......)
    {
      (RadListView1.FindControl("test") as System.Web.UI.HtmlControls.HtmlGenericControl).Visible = true;
    }
}

Thanks,
Princy.
Trudy
Top achievements
Rank 1
commented on 13 Jul 2021, 03:07 PM

How do you access the text (Outer HTML?) of a legend on the client side? I have a RadListView with a <legend> in the <LayoutTemplate and <ItemTemplate>...

<telerik:RadListView ID="RdListView_Chart" runat="server" OnNeedDataSource="RdListView_Chart_OnNeedDataSource"
OnItemDataBound="RdListView_Chart_OnItemDataBound" Width="1200"
BorderColor="#666666" BorderStyle="Solid" BorderWidth="1px" ItemPlaceholderID="FoodTestContainer" >
<LayoutTemplate>
<legend></legend>
<asp:PlaceHolder ID="FoodTestContainer" runat="server"></asp:PlaceHolder>
<div style="clear: both"></div>
</LayoutTemplate>
<ItemTemplate>
<fieldset style="float:left; width:350px; height:250px; border-color:<%#(bool)Eval("IsInvalidYN") ? "red" : "black" %>">
<legend> <%#Eval("Food") %> </legend>
[..more elements..]
</ItemTemplate>
Doncho
Telerik team
commented on 16 Jul 2021, 08:22 AM

Trudy,

You can use the embedded jQuery to get a reference to each desired HTML element in the rendered RadListView structure. Setting class names would make specific selection easier.

For instance:
<LayoutTemplate>
<legend class="LayoutLegend"></legend>

and then you can use: $telerik.$('legend.LayoutLegend')[0].outerHTML

0
Cristian
Top achievements
Rank 1
answered on 29 Jan 2013, 06:31 PM
Thanks Princy.
That worked perfectly
Tags
ListView
Asked by
Cristian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Cristian
Top achievements
Rank 1
Share this question
or