I have an int array as a property of a Web User Control. I'd like to set that property inline if possible using the following syntax:
<uc1:mycontrol runat="server" myintarray="1,2,3" />
This will fail at runtime because it will be expecting an actual int array, but a string is being passed instead. I can make myintarray
a string and parse it in the setter, but I was wondering if there was a more elegant solution.
Great snippet @mathieu. I needed to use this for converting longs, but rather than making a LongArrayConverter, I wrote up a version that uses Generics.
This version should work with any type that is convertible from string.
Do do what Bill was talking about with the list you just need to create a List property on your user control. Then you can implement it as Bill described.
You could add to the page events inside the aspx something like this:
To add child elements that make your list you need to have your control setup a certain way:
The Actions above is the name of the cproperty the child elements will be in. I use an ArrayList, as I have not testing anything else with it.:
when your contorl is initialized it will have the values of the child elements. Those you can make a mini class that just holds ints.