现有RadListView列表控件,控件中有嵌套了一个RadRating,页面布局如下:
代码如下:
<telerik:RadListView ID="RlvwCriticism" runat="server" AllowCustomPaging="true" ItemPlaceholderID="item" PageSize="8" AllowPaging="True" OnItemDataBound="RlvwCriticism_ItemDataBound" OnItemCommand="RlvwCriticism_ItemCommand" OnPageIndexChanged="RlvwCriticism_PageIndexChanged"> <EmptyDataTemplate> <div style="text-align: center;"> <span style="color: #808080; text-decoration: none;">暂无评论!</span> </div> </EmptyDataTemplate> <LayoutTemplate> <table id="item" runat="server"></table> <table> <tr> <td> <telerik:RadDataPager ID="RdpgCriticism" runat="server" CssClass="CustomDataPager" BorderWidth="0" Skin="Metro" PagedControlID="RlvwCriticism" PageSize="8"> <Fields> <telerik:RadDataPagerButtonField FieldType="FirstPrev" FirstButtonText="首页" PrevButtonText="上一页" /> <telerik:RadDataPagerButtonField FieldType="Numeric" /> <telerik:RadDataPagerButtonField FieldType="NextLast" LastButtonText="尾页" NextButtonText="下一页" /> </Fields> </telerik:RadDataPager> </td> </tr> </table> </LayoutTemplate> <ItemTemplate> <table width="720" border="0" align="center" style="color: #414141; border-bottom: 1px dotted #e5e5e5"> <tr> <td width="70" height="68" align="center" valign="middle"> <img id="Img1" src='<%#Eval("HeadSculpturePath") %>' width="50" height="50" runat="server" /></td> <td colspan="2" valign="top" style="line-height: 18px;"><span style="float: left; color: #0095c6"><%# Eval("RealName")%>:</span><span style="float: left;"><%#Eval("CriticismContent")%></span></td> </tr> <tr> <td height="24" align="center"> <telerik:RadButton ID="RbtnDelete" runat="server" Text="删除" Width="50" Skin="Metro" CommandName="Delete" CommandArgument='<%#Eval("CriticismID")%>'></telerik:RadButton> </td> <td width="517"><span style="float: left; line-height: 24px;">星级:</span><span style="float: left;"><telerik:RadRating ID="RrtReadGrade" runat="server" ReadOnly="True" Skin="Metro"></telerik:RadRating> </span></td> <td width="142"><%# Eval("CriticismTime")%></td> </tr> </table> </ItemTemplate> </telerik:RadListView>
在显示评价的时候需要显示星级,因此需要给每行都赋值,在ItemDataBound事件中写即可,给RadRating控件赋值方法如下:
protected void RlvwCriticism_ItemDataBound(object sender, RadListViewItemEventArgs e) { //读取评价星级 Telerik.Web.UI.RadRating rating = e.Item.FindControl("RrtReadGrade") as Telerik.Web.UI.RadRating; //RrtReadGrade是前台RadRating控件ID,其他控件的读取方式类似,只需将 Telerik.Web.UI.RadRating改成对应控件即可 if (rating != null) { Telerik.Web.UI.RadListViewDataItem item = e.Item as Telerik.Web.UI.RadListViewDataItem; if (item != null) { DataRowView view = item.DataItem as DataRowView; if (view != null) { int ratval = int.Parse(view["CriticismGrade"].ToString()); //将数据赋给控件 rating.Value = ratval; } } }
}
转载于:https://www.cnblogs.com/elvira/p/6432607.html