"dynamic" textbox/textarea

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
I have a checkboxlist, that can have from 1 to 32 checkboxes...

When a checkbox is clicked, I want to display a TextBox/TextArea...

How can I reserve a place for this textbox next to each checkboxlist?

How can I have it as textarea since the text can be a paragraph or more?

Is it even doable with checkboxlist??
 
eramgarden said:
I have a checkboxlist, that can have from 1 to 32 checkboxes...

When a checkbox is clicked, I want to display a TextBox/TextArea...

How can I reserve a place for this textbox next to each checkboxlist?

How can I have it as textarea since the text can be a paragraph or more?

Is it even doable with checkboxlist??


One way you could do it [probably not the best but it should work] is to put the textboxes on your webform at design, set their property to multiline (for the textarea functionality) and set their visible property to false. Then when the checkboxlist is populated or however you can use that, make the appropriate textboxes visible property be true.

Another way you might try is doing something like this:
Visual Basic:
Response.Write("<form><input type='textarea' ... ></form>")

Although, this method would take a lot more effort, it might be better. Also, you will need to set the checkboxlist to autopostback so that the page can redraw with the new features.

Good Luck!
Brian
 
Placing your controls in a table can help with your formatting problem. Within the same row you can place the checkbox into the first cell and then place the corresponding text box in a second cell.
 
One way you could do it [probably not the best but it should work] is to put the textboxes on your webform at design, set their property to multiline (for the textarea functionality) and set their visible property to false. Then when the checkboxlist is populated or however you can use that, make the appropriate textboxes visible property be true.

Getting close...

I put a checkboxlist and a textbox with multiLine at design time...The binding data to checkboxList and textbox..

I have 2 rows, for example, get 2 checkboxes BUT ONLY ONE TEXTBOX...I want to have a textbox for each checkbox in the list..

How to do this??
 
eramgarden said:
I have 2 rows, for example, get 2 checkboxes BUT ONLY ONE TEXTBOX...I want to have a textbox for each checkbox in the list..

That seems correct, unfortunately for you, because the checkbox list and the textbox are separate objects. Have you thought of using a repeater control instead? Then you can put a checkbox and textbox in it and repeat through your dataset.
 
Unfortunately I don't have time to wip up a sample but you might try researching the following approach;

1. Use a table with two cells for each row and place the CheckBoxList control in the first cell.

2. In the second cell use a <span id="TextBoxHolder" runat="server"/> tag to as a place holder.

3. During the load event setup a For loop that cycles from 0 to CheckBoxList.Items.Count-1 times. Each time through it dynamically creates a TextBox control with an id equivalent to the loop counter. Therefore, the id of the text box should be equivalent to the corresponding check box.

4. When the form is posted determine if a check box has been selected. If so use the Text property of the corresponding text box to display some message.

I think this may work for you.
Tate
 
Ooops... forgot to add how to use the <span>.

TextBoxHolder.InnerHtml = "your text box code string"
 
Back
Top