2 Replies - 179 Views - Last Post: 20 June 2012 - 07:06 AM Rate Topic: -----

#1 GordonCn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-August 11

Is it possible to dynamically set an item in an mvc model

Posted 19 June 2012 - 10:14 AM

Sorry I am not completely sure how to phrase my question, but what I am trying to do is inside a for each loop set the item of a model then set the value of that item.

dim td as new project.model.mymodel //create model object

For each dr as datarow in dt.rows
dim itemName as string = convert.tostring(dr("Field"))
td.itemName = "6"
next

I keep getting an error that itemName is not part of collection td

Any help would be appreciated.

Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible to dynamically set an item in an mvc model

#2 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 957
  • View blog
  • Posts: 3,684
  • Joined: 02-July 08

Re: Is it possible to dynamically set an item in an mvc model

Posted 19 June 2012 - 01:36 PM

What exactly is project.model.mymodel?
Was This Post Helpful? 0
  • +
  • -

#3 GordonCn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-August 11

Re: Is it possible to dynamically set an item in an mvc model

Posted 20 June 2012 - 07:06 AM

View Post_HAWK_, on 19 June 2012 - 01:36 PM, said:

What exactly is project.model.mymodel?


Sorry I was just declaring a mvc model to update the properties.
I found a solution.
I am using the built in funtion CallByName(Object, ProName, CallType, Params) to dynamically set the property values.

So it looks like this:

Dim td as myproject.model.mymodel

For each dr as datarow in dt.rows
CallByName(td, Convert.ToString(dr("Field")), CallType.Set, value)
Next

I found the solution after I figured out the correct wording of my question.
Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1