How to set ListItem properties using Reflection (VB.net).

D

dig_dug_d

Hello,

I have been struggling with the SetValue method when trying to use
indexed items. I can not figure out what needs to be done to create
the "index As Object()" parameter.

Lets say I have this in my page..

<asp:ListBox ID="ListBox1" runat="server" EnableViewState="False"
SelectionMode="Multiple">
<asp:ListItem Value="L1">List1</asp:ListItem>
<asp:ListItem Value="L2">List2</asp:ListItem>
<asp:ListItem Value="L3">List3</asp:ListItem>
</asp:ListBox>

And in the code behind I want to set the second item's selected
property to "True"... how would this be done? I'm currently working
with something like this..

Dim Element As String = "ListBox1"
Dim PropName As String = "Selected"
Dim PropValue As String = "True"
Dim Index = New Object()

Page.FindControl(Element).GetType().GetProperty(PropName).SetValue(Page.FindControl(Element),
PropValue , Index)


If I am way off and using the index parameter isn't needed.. I am sure
many people would love to see how this mysterious parameter works in a
real example.

Thanks in advance!
Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,079
Latest member
ElidaWarin

Latest Threads

Top