gpt4 book ai didi

asp.net - 如何从(对象发送者,ListViewItemEventArgs e)转换对象

转载 作者:行者123 更新时间:2023-12-02 13:53:08 24 4
gpt4 key购买 nike

我正在将 ListView 控件与以下数据源一起使用 List<MyObject>

在我的 ListView 控件上,我有一个 OnItemDataBound

我的问题是如何获取 MyObject 的当前值。即 myObj[5].FirstName

protected void ItemsListViewDataBound(对象发送者,ListViewItemEventArgs e){//我想在这里进行某种类型的转换

}

最佳答案

protected void MyListView_DataBind(object sender, ListViewItemEventArgs e){
if(e.Item.ItemType == ListViewItemType.DataItem){
MyObject p = (MyObject)((ListViewDataItem)e.Item).DataItem;
}
}

您需要进行类型检查,这样您在处理标题项时就不会尝试进行强制转换。

关于asp.net - 如何从(对象发送者,ListViewItemEventArgs e)转换对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/388468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com