Passing int list as a parameter to a web user control

前端 未结 8 1526
失恋的感觉
失恋的感觉 2020-12-14 04:15

I want to pass an int list (List) as a declarative property to a web user control like this:


         


        
8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 04:33

    You can pass it into a string and split on comma to populate a private variable. Does not have the nicety of attribution, but will work.

    private List modules;
    public string ModuleIds
    {
      set{
        if (!string.IsNullOrEmpty(value))
        {
        if (modules == null) modules = new List();
        var ids = value.Split(new []{','});
        if (ids.Length>0)
          foreach (var id in ids)
            modules.Add((int.Parse(id)));
        }
    }
    

提交回复
热议问题