Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...