我有一个数据列表控件,它通过以下方式由数据源填充: 我想检查客户类型是否具有 R、P、Y 之类的值,如果是,我只想在下面的数据列表控件中将整个文本的 CutomerName 部分加粗。请指导我。谢谢
<asp:DataList ID="Customer" runat="server"
DataSourceID="CustomerIndicatorSource" RepeatColumns="2"
DataKeyField="CustomerIndicatorID" Width="100%"
onitemdatabound="CustomerIndicators_ItemDataBound"
style="font-size:x-small; line-height:normal">
<ItemTemplate>
<asp:Label ID="Label1" runat ="server" Text='<%# Eval("CustomerType") + Eval("CustomerName") %>' Width="300px"></asp:Label>
</ItemTemplate>
</asp:DataList>
最佳答案
在您的 onitemdatabound 方法 CustomerIndicators_ItemDataBound 中,您应该能够检查被绑定(bind)元素的值,获取标签,并根据它进行编辑。这尚未经过测试,但它应该让您大致了解如何进行此操作。
void CustomerIndicators_ItemDataBound (Object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
Label CustomerTypeLabel = (Label)e.Item.FindControl("Label1");
DataRowView drv= ((DataRowView)e.Item.DataItem).ToString();
string CustomerType = drv.Row["CustomerType"].ToString();
switch(CustomerType){
case "R":
case "P":
case "Y":
CustomerTypeLabel.Font.Bold = true;
break;
}
}
这些链接包含更多信息。
http://msdn.microsoft.com/en-us/library/6y92e1ze(v=vs.85).aspx http://msdn.microsoft.com/en-us/library/system.data.datarowview%28v=vs.110%29.aspx
关于c# - 数据列表控制文本搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27362814/