I need to set the text attributes for different languages.
9 Answers, 1 is accepted
Merely invoking the FindControl(labelId) method for the RadListView instance should be sufficient to locate the controls inside its layout template. This can be done inside the PageLoad handler of the page, for example:
C#
(RadListView1.FindControl("lblForum") as Label).Text = ....
VB.NET
CType(RadListView1.FindControl("lblForum"), Label).Text = .....
Best regards,
Sebastian
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.
When I tried it, it didn't work. But I found out it depends on the page event in wich you use this statement.
De control is not yet defined in the page_load event.
When I used it in the RadListView1_PreRender event it worked fine.
Listen for the ItemCreated server event of the listview for this purpose. This code worked as expected on my end:
<asp:ScriptManager ID="ScriptManager1" runat="server" /> |
<telerik:RadListView ID="RadListView1" DataSourceID="SqlDataSource1" runat="server" |
ItemPlaceholderID="ProductItemContainer" Skin="" |
onitemcreated="RadListView1_ItemCreated"> |
<LayoutTemplate> |
<fieldset id="ProductItemContainer" runat="server" /> |
</LayoutTemplate> |
<ItemTemplate> |
<ul> |
<li> |
<label> |
Product name:</label> |
<%#Eval("ProductName")%> |
</li> |
<li> |
<label> |
Quantity per unit:</label> |
<%#Eval("QuantityPerUnit")%> |
</li> |
<li> |
<label> |
Unit price:</label> |
<%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:C}")%> |
</li> |
<li> |
<label> |
Units in stock:</label> |
<%#Eval("UnitsInStock")%> |
</li> |
<li> |
<label> |
Discontinued:</label> |
<%#Eval("Discontinued")%> |
</li> |
</ul> |
</ItemTemplate> |
<EmptyDataTemplate> |
<asp:Label ID="lblEmpty" runat="server" Text="No data" /> |
</EmptyDataTemplate> |
</telerik:RadListView> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" |
ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 3 ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock, Discontinued FROM Products WHERE 1=0" /> |
protected void RadListView1_ItemCreated(object sender, RadListViewItemEventArgs e) |
{ |
if (e.Item is RadListViewEmptyDataItem) |
{ |
Label lbl1 = e.Item.FindControl("lblEmpty") as Label; |
lbl1.Text = "No data available"; |
} |
} |
Kiara
<telerik:RadListView ID="RLVTEST" runat="server" RenderMode="Lightweight" ItemPlaceholderID="itemPlaceholder" AllowPaging="True" PageSize="5"
DataKeyNames="G,M,GID" ClientDataKeyNames="G,M,GID" OnItemCommand="RLVTEST_ItemCommand" BorderWidth="0px">
<LayoutTemplate>
<div class="RadListView RadListView_<%# Container.Skin %>" style="border-width: 0px; width: 100%;">
<fieldset id="FieldSet1" style="border-width: 0px; width: 100%;">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</fieldset>
</div>
</LayoutTemplate>
<ItemTemplate>
</ItemTemplate>
<EmptyDataTemplate>
<div >
<div class="rlvEmpty">
<asp:Label ID="LB_MSG" runat="server" Text="no data"></asp:Label>
</div>
</div>
</EmptyDataTemplate>
</telerik:RadListView>
How can i change Label:LB_MSG text from EmptyDataTemplate Code Behind???
Using the approach suggested by Kiara will allow you to change the text of the label as follows:
<
telerik:RadListView
ID
=
"RLVTEST"
runat
=
"server"
RenderMode
=
"Lightweight"
ItemPlaceholderID
=
"itemPlaceholder"
AllowPaging
=
"True"
PageSize
=
"5"
DataKeyNames
=
"G,M,GID"
ClientDataKeyNames
=
"G,M,GID"
OnItemCommand
=
"RLVTEST_ItemCommand"
BorderWidth
=
"0px"
OnItemCreated
=
"RadListView1_ItemCreated"
>
<
LayoutTemplate
>
<
div
class="RadListView RadListView_<%# Container.Skin %>" style="border-width: 0px; width: 100%;">
<
fieldset
id
=
"FieldSet1"
style
=
"border-width: 0px; width: 100%;"
>
<
asp:PlaceHolder
ID
=
"itemPlaceholder"
runat
=
"server"
></
asp:PlaceHolder
>
</
fieldset
>
</
div
>
</
LayoutTemplate
>
<
ItemTemplate
>
</
ItemTemplate
>
<
EmptyDataTemplate
>
<
div
>
<
div
class
=
"rlvEmpty"
>
<
asp:Label
ID
=
"LB_MSG"
runat
=
"server"
Text
=
"no data"
></
asp:Label
>
</
div
>
</
div
>
</
EmptyDataTemplate
>
</
telerik:RadListView
>
protected
void
RadListView1_ItemCreated(
object
sender, RadListViewItemEventArgs e)
{
var type = e.Item.GetType().FullName;
if
(e.Item
is
RadListViewEmptyDataItem)
{
Label lbl1 = e.Item.FindControl(
"LB_MSG"
)
as
Label;
lbl1.Text =
"No data available"
;
}
}
Regards,
Vessy
Progress Telerik
You are welcome, howard - I am glad my reply helped you to achieve your goal :)
Regards,
Vessy
Progress Telerik