Getting CheckBoxList Item values

前端 未结 8 824
野的像风
野的像风 2021-01-04 10:53

I have a CheckBoxList which I\'m populating with data. When I attempt to retrieve the checked items from the list I can only grab the item ordinal, I cannot get the value.

8条回答
  •  太阳男子
    2021-01-04 10:59

    You can initialize a list of string and add those items that are selected.

    Please check code, works fine for me.

    List modules = new List();
    
    foreach(ListItem s in chk_modules.Items)
    {
        if (s.Selected)
        {
             modules.Add(s.Value);
        }
    }
    

提交回复
热议问题