asp:boundfield html,扩展(ASP.NET)BoundField

未经测试:

public class HighlightBoundField : DataControlField {

//property to indicate if this field should be highlighted, given the value of this property

//

public string HighlightField {

get {

object value = ViewState["HighlightField"];

if (value != null) {

return Convert.ToString(value);

}

return "";

}

set {

ViewState["HighlightField"] = value;

OnFieldChanged();

}

}

//property to display as text in the cell

//

public string DataField {

get {

object value = ViewState["DataField"];

if (value != null) {

return value.ToString();

}

return string.Empty;

}

set {

ViewState["DataField"] = value;

OnFieldChanged();

}

}

//bound field creation

//

protected override DataControlField CreateField() {

return new BoundField();

}

//override the method that is used to populate and format a cell

//

public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) {

base.InitializeCell(cell, cellType, rowState, rowIndex);

//if this celltype is a data row

//

if (cellType == DataControlCellType.DataCell && !string.IsNullOrEmpty(HighlightField)) {

//create label control to display text

//

var lblText = new Label();

//add event listener for when the label is bound

//

lblText.DataBinding += new EventHandler(lblText_DataBinding);

//add label to controls collection

//

cell.Controls.Add(lblText);

}

}

void lblText_DataBinding(object sender, EventArgs e) {

//retrieve data item and set label text

//

Label lblText = (Label) sender;

object dataItem = DataBinder.GetDataItem(lblText.NamingContainer);

lblText.Text = DataBinder.GetPropertyValue(dataItem, DataField).ToString();

//check if value should be highlighted

//

if (Convert.ToBoolean(DataBinder.GetPropertyValue(dataItem, HighlightField))) {

lblText.Style.Add("background-color", "yellow");

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<asp:BoundField DataField="ItemCode" HeaderText="产品编码 " SortExpression="ItemCode" /> <asp:BoundField DataField="ItemName" HeaderText="产品名称 " SortExpression="ItemCode" /> <asp:BoundField DataField="LibraryCollar" HeaderText="预警库龄天数" HeaderStyle-Width="100px" SortExpression="LibraryCollar" /> <asp:BoundField DataField="TotalBalanceQty" HeaderText="可用库存" HeaderStyle-Width="100px" SortExpression="TotalBalanceQty" /> <asp:BoundField DataField="MaximumInventory" HeaderText="最大库存" HeaderStyle-Width="100px" SortExpression="MaximumInventory" /> <asp:BoundField DataField="SafetyStock" HeaderText="安全库存数" HeaderStyle-Width="100px" SortExpression="SafetyStock" /> <asp:BoundField DataField="CreateBy" HeaderText="<%$ Resources:lang,CreateBy%>" SortExpression="CreateBy" HeaderStyle-Width="60px" /> <asp:BoundField DataField="CreateDateTime" HeaderText="<%$ Resources:lang,CreateDateTime%>" SortExpression="CreateDateTime" HeaderStyle-Width="140px" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" /> <asp:BoundField DataField="ModifyBy" HeaderText="<%$ Resources:lang,ModifyBy%>" SortExpression="ModifyBy" HeaderStyle-Width="60px" /> <asp:BoundField DataField="ModifyDateTime" HeaderText="<%$ Resources:lang,ModifyDateTime%>" SortExpression="ModifyDateTime" HeaderStyle-Width="140px" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" /> <asp:BoundField DataField="Status" HeaderText="状态 " SortExpression="Status" />可用库存大于最大库存时本条数据变红
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值