开发者

what is the problem with itemdatabound event in listview?

开发者 https://www.devze.com 2023-01-07 03:23 出处:网络
i am getting the following errorduring itemdataboundevent of a listview. Description: An error occurred during the compilation of a resource required to service this request. Please review the follow

i am getting the following error during itemdataboundevent of a listview.

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0030: Cannot convert type 'System.Web.UI.Web开发者_StackOverflowControls.ListViewItemType' to 'System.Data.DataRowView'

Source Error:

   Line 91:             CheckBox chk = (CheckBox)e.Item.FindControl("chkFocusArea");
Line 92:            
Line 93:             System.Data.DataRowView rowView = (System.Data.DataRowView)e.Item.ItemType; 
Line 94:             
Line 95:         }

my code behind for itembound event is

protected void lvFocusArea_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    if (e.Item.ItemType == ListViewItemType.DataItem)
    {
        CheckBox chk = (CheckBox)e.Item.FindControl("chkFocusArea");

        System.Data.DataRowView rowView = (System.Data.DataRowView)e.Item.ItemType; 

    }
}


You are using the wrong property. Cast first to ListViewDataItem and use DataItem instead of ItemType:

C#

ListViewDataItem dataItem = (ListViewDataItem)e.Item;
System.Data.DataRowView rowView = (System.Data.DataRowView)dataItem.DataItem;

VB.NET

Dim dataItem As ListViewDataItem = CType(e.Item, ListViewDataItem)
Dim rowView As System.Data.DataRowView = CType(dataItem.DataItem, DataRowView)
0

精彩评论

暂无评论...
验证码 换一张
取 消