This is a migrated thread and some comments may be shown as answers.

Problem binding to a list(of Pair)

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 26 Nov 2008, 07:59 PM
Hello

I am using radgrid 5.1.2. I am binding the grid to a List(of Pair) objects. Here is the code to bind the grid

 

Dim stockList As List(Of Pair) = CType(Session("StockList"), List(Of Pair))

 

stockList.Insert(0,

 

 

 

 

New Pair(stockCode, stockType))

 

dgStock.DataSource = stockList

dgStock.DataBind()

I have checked that the stock list definitely has some items in it at this point. In the item data bound event however it is saying the data item is not set to an instance of an object. Here is the code

 

 

 

 

 

 

Protected Sub dgStock_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.WebControls.GridItemEventArgs) Handles dgStock.ItemDataBound

 

 

 

 

 

 

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

 

 

 

 

 

 

 Throw New Exception(e.Item.DataItem Is Nothing) <====says TRUE

 

 

 

 

 

 

 

 

 

 

 

 


At this point the dataItem object is nothing. I don't understand why this is. I tried the same thing using an array of string and the data item was still nothing.


Please can you helpme fix this
thanks

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 Nov 2008, 07:07 AM
Hi andieje,

Generally ListItemType.Item and ListItemType.AlternatingItem are applicable only for MS list controls not for RadGrid. To achieve your goal you should use:

If TypeOf e.Item Is GridDataItem Then

Greetings,
Vlad
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or