views:

128

answers:

1

Hello,

I have some checkboxlist like this:

    <asp:CheckBoxList ID="G1" runat="server">
                        <asp:ListItem Value="Comunicações Unificadas" Text="Comunicações Unificadas - UCoIP"></asp:ListItem>
                        <asp:ListItem Value="Gestão Documental" Text="Gestão Documental - iPortalDoc"></asp:ListItem>
                        <asp:ListItem Value="Gestão Conteúdos Web" Text="Gestão de Conteúdos Web"></asp:ListItem>
                        <asp:ListItem Value="Promoção Websites" Text="Promoção de Websites"></asp:ListItem>
                        <asp:ListItem Value="Serviços de Consultoria" Text="Serviços de Consultoria"></asp:ListItem>
</asp:CheckBoxList>

When submitting the form than contains them, i want to save all the selected values in a xml file.

At the moment if i select more than one value to submit, in the xml file i only get the first selected, the others do not appear in the file.

I'm saving the values in the xml file this way:

Dim doc As New XmlDocument() doc.Load(LocalizacaoFicheiro)

    Dim visitor As XmlElement = doc.CreateElement("Cliente")

    Dim res1 As XmlElement = doc.CreateElement("Resposta1")
    res1.InnerText = G1.SelectedValue.ToString


    visitor.AppendChild(res1)

    doc.DocumentElement.AppendChild(visitor)

    doc.Save(LocalizacaoFicheiro)

I need to change something in the way that i save the data to xml, right?

A: 

CheckBoxList.SelectedValue is just a single value, so of course you're only getting one value when you use that property. From its definition it's designed to give you only the first selected value:

If multiple items are selected, the value of the selected item with the lowest index is returned.

Use CheckBoxList.Items instead, looping through all of them and checking the ListItem.Selected property to see if they've been selected or not. (Or use the equivalent LINQ expression, whichever you prefer.)

Welbog