Get specific item value from the Repeater.Item.DataItem

Retrieve specific value from the Repeater.Item.DataItem in your code.

Ok so I searched around for how to get specific value from a Repeater.Item.DataItem and found a common answer:

In an effort to cast the item to an object the following error kept popping up was this would through and error:

Unable to cast object of type '<>f__AnonymousType0`2[System.String,System.Int32]' to type 'System.Data.DataRowView'

What I discovered was that I was trying to cast an Anonymous Object into something that was not Anonymous and this just isn’t possible in .Net.

I did finally discover that I could assign the Repeater.Item.DataItem to a dynamic data type. Then I could just access the value just like a property.

Then I could do this:

[code lang=”csharp”] var query = (from DataRow dr in dtBookInfo.Rows
where dr[“vchBookStructureName”].ToString().Contains(temp.vchBookStructureName)
select new { vchTypeName = (string)dr[“vchTypeName”] }).Distinct();

Probably pretty simple for a more advanced developer, but when I started this it was a pain to figure out. Getting a specific value from the Repeater.Item.DataItem can be a bit of a pain, but as you work through it everything makes more sense. The more practice with these types of controls the better you will get at figuring out what you can and cannot do with them.

Hope this helps you with your project.