burak Posted July 23, 2003 Posted July 23, 2003 Hello, I have a form, with a checkboxlist control and an image button. <form id="Form1" method="post" runat="server"> <asp:checkboxlist id="Checkboxlist2" DataValueField="company_name" TextAlign="right" DataTextField="company_name" DataTextFormatString=" {0}" Runat="server"> </asp:checkboxlist> <asp:ImageButton id="imgSubmit" ImageUrl="images/submit.gif" Runat="server"> </asp:ImageButton> When the page loads, the checboxlist control gets populated with data from the database. So I end up with 4 checkboxes with descriptions next to them. I then check some of the checkboxes and then click the "submit" image button. This function gets called Private Sub imgSubmit_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgSubmit.Click Dim s As String Dim i As Integer s = "Selected items:<br>" For i = 0 To Checkboxlist2.Items.Count - 1 If Checkboxlist2.Items(i).Selected Then s = s & Checkboxlist2.Items(i).Text & "<br>" End If Next i Response.Write(s) End Sub But for some reason the checked checkboxes get unchecked after submission of the form and it looks as if nothing was selected. Do you know how I can fix this? Thank you, Burak Quote
Moderators Robby Posted July 23, 2003 Moderators Posted July 23, 2003 Since the checkboxes are getting their values from a database, then on postback they are getting the same values (from the DB). What you need to do is not reload the checkboxes if IsPostBack is True. Quote Visit...Bassic Software
burak Posted July 24, 2003 Author Posted July 24, 2003 Thank you Robby. I am also trying to figure out how to arrange the description of the checkbox so that it lines up left centered and couple of spaces away from the checkbox. In the asp code, this is easy because the checkbox and the description are on separate columns. <td class="left"> <input name="task" type="checkbox" id="task"> </td> <td class="left"> rsData("tasks") </td> So we get a checkbox and left centered description that looks like this: - Teach courses pertaining to the chemical and | | physical properties and compositional changes of - substances. In the .net code, the checkboxlist control is in one column, hence both the checkbox and the description show up in the same column. <td> <asp:checkboxlist id="Checkboxlist2" DataValueField="company_name" TextAlign="right" DataTextField="company_name" DataTextFormatString=" {0}" Runat="server"></asp:checkboxlist> </td> and we end up with - | | Teach courses pertaining to the chemical and - physical properties and compositional changes of substances. which does not look good. I suspect the solution might have something to do with RenderBeginTag and RenderEndTag methods, but I am not sure. Do you know how I can format the text so it appears like the asp version? Thanks, Burak Quote
burak Posted July 24, 2003 Author Posted July 24, 2003 Correction: The asp checkbox looks like this - Teach courses pertaining to the chemical and | | physical properties and compositional changes of - substances. the .net checkbox looks like this - | | Teach courses pertaining to the chemical and - physical properties and compositional changes of substances. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.