0

I found a few where they past the item instead of the value. i want the value to be passed. for e.g

<asp:CheckBoxList ID="cblPlanets" runat="server" Width="109px">    
<asp:ListItem Value="1">Mercury</asp:ListItem>    
<asp:ListItem Value="2">Venus</asp:ListItem>    
<asp:ListItem Value="3">Earth</asp:ListItem>    
<asp:ListItem Value="4">Mars</asp:ListItem>    
<asp:ListItem Value="5">Jupiter</asp:ListItem>    
<asp:ListItem Value="6">Saturn</asp:ListItem>
</asp:CheckBoxList>

and i want it to display

You selected:
1
2
3
6

the back end part i did was

Label1.Text = "You Selected:<br /><i>"
        For Each li As String In CBInsurance.SelectedValue
            If li.ToString = True Then
                Label1.Text += li.ToString & "<br />"
            End If
        Next
        Label1.Text += "</i>"

but it only display one value. instead of multiple value

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by mIssy_ricco
0

I found a few where they past the item instead of the value. i want the value to be passed. for e.g

<asp:CheckBoxList ID="cblPlanets" runat="server" Width="109px">    
<asp:ListItem Value="1">Mercury</asp:ListItem>    
<asp:ListItem Value="2">Venus</asp:ListItem>    
<asp:ListItem Value="3">Earth</asp:ListItem>    
<asp:ListItem Value="4">Mars</asp:ListItem>    
<asp:ListItem Value="5">Jupiter</asp:ListItem>    
<asp:ListItem Value="6">Saturn</asp:ListItem>
</asp:CheckBoxList>

and i want it to display

You selected:
1
2
3
6

the back end part i did was

Label1.Text = "You Selected:<br /><i>"
        For Each li As String In CBInsurance.SelectedValue
            If li.ToString = True Then
                Label1.Text += li.ToString & "<br />"
            End If
        Next
        Label1.Text += "</i>"

but it only display one value. instead of multiple value

Hi
Because your selected item is only one.
you can use if i understood you correcly!!! do your stuff in for loop

for i=0 to CBInsurance.items.count-1
next

Edited by reach_yousuf: n/a

0

im sorry. but can u explain further.

the one i received before was

Label1.Text = "You Selected:<br /><i>"
        For Each li As ListItem In CBInsurance.Items
            If li.Selected = True Then
                Label1.Text += li.Text & "<br />"
            End If
        Next
        Label1.Text += "</i>"

and it helps if i want to display the text

for e.g it will appear

You Selected:
Mercury
Venus
etc...whatever you checked on.

0

Hi there
code for you!!!

Protected Sub ibtnCancel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnCancel.Click
        Dim i As Integer
        txtProductName.Text = ""
        For i = 0 To cblPlanets.Items.Count - 1
            If cblPlanets.Items(i).Selected = True Then
                If i = 0 Then
                    txtProductName.Text = "U have selected " & cblPlanets.SelectedItem.Text
                Else
                    txtProductName.Text += "," & cblPlanets.Items(i).Text
                End If
            End If
        Next
    End Sub

Mark as solved if it helps you!!!

Edited by reach_yousuf: n/a

0

Hi there
code for you!!!

Protected Sub ibtnCancel_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnCancel.Click
        Dim i As Integer
        txtProductName.Text = ""
        For i = 0 To cblPlanets.Items.Count - 1
            If cblPlanets.Items(i).Selected = True Then
                If i = 0 Then
                    txtProductName.Text = "U have selected " & cblPlanets.SelectedItem.Text
                Else
                    txtProductName.Text += "," & cblPlanets.Items(i).Text
                End If
            End If
        Next
    End Sub

Mark as solved if it helps you!!!

it didn't help. it passed me the item as well..it shows

U have selected Mercury,Venus,Earth

i want

U have selected 1,2,3

1

it didn't help. it passed me the item as well..it shows

U have selected Mercury,Venus,Earth

i want

U have selected 1,2,3

Change the following line

txtProductName.Text += "," & cblPlanets.Items(i).Value

Pls. Mark as solved!!!

Edited by reach_yousuf: n/a

0

i got it already. thanks. and yes i used

cblPlanets.Items(i).Value

. thanks for your time :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.