c# - 数据列表控制文本搜索

标签 c# css datalist

我有一个数据列表控件,它通过以下方式由数据源填充: 我想检查客户类型是否具有 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/

相关文章:

css - 位置固定时隐藏在内容后面的网站标题

javascript - 无法从 Chrome 64 中的本地 css 文件访问 cssRules

c# - Asp.Net DataList 绑定(bind) ImageUrls 数组

c# - linq2sql图片保存问题

c# - 使用 finally 而不是 catch

JQuery 对话框标题栏和关闭按钮不可见

html - 菜单项隐藏在数据列表后面

c# - 从可能性集中找出所有组合

c# - 如何等待后台 worker 完成处理?

c# - 无法触发数据列表中的 DeleteCommand