|
-
Oct 24th, 2003, 02:11 PM
#1
Thread Starter
Member
check box lst problem - help ? - resolved
hi
i have a check box list in page and a button when i check some items and submit by button i am not able to read the selected items or checked items status at server. is there a way to it or i am doing it wrong this is the code
sub buton1_click(sender as object, e as eventargs)
Dim i As Integer
For i=0 To checkboxlist1.Items.Count - 1
If checkboxlist1.Items(i).Selected Then
response.write( checkboxlist1.Items(i).Text + "<br>")
End If
Next
end sub
thanks in advance --
Last edited by kanakaprasad; Oct 27th, 2003 at 08:51 AM.
Kanaka Prasad
-
Oct 25th, 2003, 12:22 PM
#2
Hyperactive Member
VB Code:
<%@ Import Namespace="System.Collections" %>
<script language="vb" runat="server">
Protected Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs)
For index As Integer = 0 To cblTest.Items.Count - 1
If cblTest.Items(index).Selected Then
Response.Write(cblTest.Items(index).Text)
Response.Write(" is selected.<br/>")
End If
Next
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
bindCheckBoxList
End If
End Sub
Private Sub bindCheckBoxList()
Dim items As New ArrayList()
items.Add("Item 1")
items.Add("Item 2")
items.Add("Item 3")
cblTest.DataSource = items
cblTest.DataBind
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:CheckBoxList ID="cblTest" Runat="server"/><br/>
<asp:Button ID="btnTest" Runat="server" Text="Test"
OnClick="btnTest_Click"/>
</form>
</body>
</html>
The only way this didn't work is if, in the OnLoad Sub, I don't check for Page.IsPostBack. The OnLoad method or Page_Load eventhandler, will fire before the the button click event is processed. So perhaps you are rebinding on postback and wiping out anything you selected before posting; then in the button click event nothing would be selected.
Last edited by pvb; Oct 25th, 2003 at 12:26 PM.
-
Oct 26th, 2003, 11:52 AM
#3
Thread Starter
Member
i think thats what i am doing wrong. i am not checking for the ispostback. thanks alot i shall work onit and let you know. thanks once again
kanaka
-
Oct 27th, 2003, 08:51 AM
#4
Thread Starter
Member
resolved - thanks
the problem is solved thanks folks
kanak a
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|