How can I get the CheckBoxList selected values, what I have doesn't seem to work C#.NET/VisualWebPart

后端 未结 6 2109
盖世英雄少女心
盖世英雄少女心 2020-11-30 07:53

I am creating a CheckBoxList in a class file and am using an HTMLTextWriter to render the control.

I\'m using the following code to store the selected values in a s

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 08:26

    // aspx.cs

    // Load CheckBoxList selected items into ListBox

        int status = 1;
        foreach (ListItem  s in chklstStates.Items  )
        {
            if (s.Selected == true)
            {
                if (ListBox1.Items.Count == 0)
                {
                    ListBox1.Items.Add(s.Text);
    
                }
                else
                {
                    foreach (ListItem list in ListBox1.Items)
                    {
                        if (list.Text == s.Text)
                        {
                            status = status * 0;
    
                        }
                        else
                        {
                            status = status * 1;
                        }
                    }
                    if (status == 0)
                    { }
                   else
                    {
                        ListBox1.Items.Add(s.Text);
                    }
                    status = 1;
                }
            }
        }
    }
    

提交回复
热议问题