[英]How do I change a ListView dynamically on DataBound?
我有一個帶模板的ListView,它放入一堆數據,例如XYZ。
我想隱藏顯示基於條件的某些列,所以我有ItemDataBound事件,但是我不知道如何獲取實際的listview行,因此我可以做一些事情。
有任何想法嗎?
您可以訪問ListViewItemEventArgs的Item屬性以獲取當前項(與數據綁定的項)。
下面的示例代碼(顯示了如何在ItemDataBound事件中自定義ListView項)摘自MSDN文檔 :
protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
Label EmailAddressLabel;
if (e.Item.ItemType == ListViewItemType.DataItem)
{
// Display the e-mail address in italics.
EmailAddressLabel = (Label)e.Item.FindControl("EmailAddressLabel");
EmailAddressLabel.Font.Italic = true;
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
string currentEmailAddress = rowView["EmailAddress"].ToString();
if (currentEmailAddress == "orlando0@adventure-works.com")
{
EmailAddressLabel.Font.Bold = true;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.