触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > DataList的ItemDataBound处理字加粗

.net中DataList的ItemDataBound处理

也就是说先取得数据库中的每行每列数据,在赋给指定的控件

例一:文字提示
假设在DataList的ItemTemplate里增加了一个:
<asp:Label ID="LabelAdded" runat="server" />

protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  {
  DataRowView drv = e.Item.DataItem as DataRowView;

  Label label = e.Item.FindControl("LabelAdded") as Label;
  if (Convert.ToDecimal(drv["价格字段名"]) >= 20.0m)
  {
  label.Text = "太贵了!";
  }
  else
  label.Text = "便宜货!";
  }
}

例二:加粗
        protected void DataListanews2_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            //if (e.Item.ItemIndex == 0)
            //{
            //    e.Item.Font.Bold = true;
            //}
            DataRowView drv = e.Item.DataItem as DataRowView;
            if (Convert.ToInt32(drv["state"]) == 1)
            {
                e.Item.Font.Bold = true;
            }
        }


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com