ItemDataBound事件,可在此事件中更改属性最终显示值,以下为后代码文件:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//当前状态
Label lblCurStatus = (Label)e.Item.FindControl("lblCurState");
//上级目录
Label lblParent = (Label)e.Item.FindControl("lblParentID");
if (lblCurStatus.Text.ToString() == "1")
{
lblCurStatus.Text = "正常";
}
else if (lblCurStatus.Text.ToString() == "0")
{
lblCurStatus.Text = "关闭";
}
//绑定上级目录
if (lblParent.Text.ToString().Trim() == "0")
{
lblParent.Text = "无上级目录";
}
else
{
DataTable dtParent = Area_BLL.GetAreaTitle(int.Parse(lblParent.Text.ToString().Trim()));
if (dtParent.Rows.Count > 0)
{
lblParent.Text = dtParent.Rows[0][0].ToString().Trim();
}
}
}
}
以下为页面代码文件:
以上DataKeyField的值必须为主键值。
也可以在此事件中做子DataList的嵌套使用。
阅读(3481) | 评论(0) | 转发(0) |