473,663 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamic checkbox list challenge galore


I'm dynamically creating/populating a checkbox list and adding it to a web
form.
I want to when checking an item in the list have the autopostback retrieve
the
selected item.

I'm dynamically adding that control as:
Protected WithEvents userSelectionLi st, Ulist2 As
System.Web.UI.W ebControls.Chec kBoxList
Protected WithEvents checkboxcontain er As PlaceHolder

For i = 0
Dim selectedItem As New ListItem(appstr ing, appstring)
'selectedItem.S elected = True
userselectionli st.Items.Add(se lectedItem)
Next i

checkboxcontain er.Controls.Add (userselectionl ist)

etc..
td1.Controls.Ad d(checkboxconta iner)
tr1.Controls.Ad d(td1)
table1.Controls .Add(tr1)
form1.Controls. Add(table1)

My asp looks something like this:

<form id="Form1" method="post" runat="server">
<asp:Table Runat="server" ID="Table1">
<asp:TableRow ID='appinfo' Visible=false Width='250'>
<asp:TableCel l ID='appname' Visible=true ColumnSpan="1"
HorizontalAlign ="Right">
<br>
<asp:Literal id="mySelection s" Runat="server"> </asp:Literal>
<asp:PlaceHolde r ID="checkboxcon tainer" Runat="server" />
<asp:CheckBoxLi st ID="mylist" Runat="server" />
<br>
</asp:TableCell>
</asp:TableRow>

And retrieving the list on the postback which I'm calling in page_init:

Sub apppb()
Dim i, x As Integer

'Dim userSelectionLi st As New CheckBoxList
userSelectionLi st = CType(form1.Fin dControl("mylis t"), CheckBoxList)
Ulist2 = CType(form1.Fin dControl("mylis t"), CheckBoxList)
Try
For x = 0 To Ulist2.Items.Co unt - 1
If Ulist2.Items(x) .Selected = True Then
results.Text += Ulist2.Items(x) .Value
'mySelections.T ext += userSelectionLi st.Items(x).Val ue

End If
Next x
Catch ex As Exception

End Try
End Sub

Yet no value for the selected item.

Please help. I've used dynamic controls before and I think
maybe there may be a problem when I redeclare the control
for viewstate on the postback i.e.:

There are some complications in finding the checkboxlist control maybe because
it's binded to a placeholder - checkboxcontain er.

My page init looks something like:

InitializeCompo nent()
If Not IsPostBack Then
buildform(sende r, e)
Else

'userSelectionL ist = New CheckBoxList
'checkboxcontai ner = New PlaceHolder
'userSelectionL ist = CType(form1.Fin dControl("mylis t"),
CheckBoxList)
'checkboxcontai ner.Controls.Ad d(userSelection List)
'checkcontainer ()
buildform(sende r, e)
apppb()

End If

Can someone get this scenario to work?

Regards;

tjt:
Nov 19 '05 #1
1 2562
segue,

In the CBL's properties, set AutoPostBack = true

As well, you will want to set up a server side event that is called
whenever a user clicks the checkbox (the click event). THis way you can
get the sender, and the EventArgs from the postback and figure out what
Item called the post back.

/RT
segue wrote:
I'm dynamically creating/populating a checkbox list and adding it to a web
form.
I want to when checking an item in the list have the autopostback retrieve
the
selected item.

I'm dynamically adding that control as:
Protected WithEvents userSelectionLi st, Ulist2 As
System.Web.UI.W ebControls.Chec kBoxList
Protected WithEvents checkboxcontain er As PlaceHolder

For i = 0
Dim selectedItem As New ListItem(appstr ing, appstring)
'selectedItem.S elected = True
userselectionli st.Items.Add(se lectedItem)
Next i

checkboxcontain er.Controls.Add (userselectionl ist)

etc..
td1.Controls.Ad d(checkboxconta iner)
tr1.Controls.Ad d(td1)
table1.Controls .Add(tr1)
form1.Controls. Add(table1)

My asp looks something like this:

<form id="Form1" method="post" runat="server">
<asp:Table Runat="server" ID="Table1">
<asp:TableRow ID='appinfo' Visible=false Width='250'>
<asp:TableCel l ID='appname' Visible=true ColumnSpan="1"
HorizontalAlign ="Right">
<br>
<asp:Literal id="mySelection s" Runat="server"> </asp:Literal>
<asp:PlaceHolde r ID="checkboxcon tainer" Runat="server" />
<asp:CheckBoxLi st ID="mylist" Runat="server" />
<br>
</asp:TableCell>
</asp:TableRow>

And retrieving the list on the postback which I'm calling in page_init:

Sub apppb()
Dim i, x As Integer

'Dim userSelectionLi st As New CheckBoxList
userSelectionLi st = CType(form1.Fin dControl("mylis t"), CheckBoxList)
Ulist2 = CType(form1.Fin dControl("mylis t"), CheckBoxList)
Try
For x = 0 To Ulist2.Items.Co unt - 1
If Ulist2.Items(x) .Selected = True Then
results.Text += Ulist2.Items(x) .Value
'mySelections.T ext += userSelectionLi st.Items(x).Val ue

End If
Next x
Catch ex As Exception

End Try
End Sub

Yet no value for the selected item.

Please help. I've used dynamic controls before and I think
maybe there may be a problem when I redeclare the control
for viewstate on the postback i.e.:

There are some complications in finding the checkboxlist control maybe because
it's binded to a placeholder - checkboxcontain er.

My page init looks something like:

InitializeCompo nent()
If Not IsPostBack Then
buildform(sende r, e)
Else

'userSelectionL ist = New CheckBoxList
'checkboxcontai ner = New PlaceHolder
'userSelectionL ist = CType(form1.Fin dControl("mylis t"),
CheckBoxList)
'checkboxcontai ner.Controls.Ad d(userSelection List)
'checkcontainer ()
buildform(sende r, e)
apppb()

End If

Can someone get this scenario to work?

Regards;

tjt:

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13214
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
0
1407
by: Scott P. | last post by:
I'm creating an app using ASP .NET (my second app so bear with me here) that basically builds a PDF file based on a bunch of user selections. I have a page which displays a series of checkboxs using the checkbox object. These are all created on-the-fly using the following code: While dtrSelect.Read Dim DocumentRow As New TableRow Dim DocumentCell As New TableCell Dim DocumentCell1 As New TableCell Dim chkDocument As CheckBox
3
3973
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
4
5033
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+ fields of information per product so they're selecting a subset of those fields to edit.
4
467
by: Mike | last post by:
I'm having a problem which I thought would be a very simple thing but is turning out to be a difficult challenge. I have a web form with several input fields and I have a single checkbox, not a checkbox list. Before the form can be submitted I want to require that the checkbox be checked. Sounds simple but non of the validation controls seem to work correct for this, or maybe I'm just not using them correctly. I have done several searches...
2
7046
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
0
1515
by: TarekSaad | last post by:
I am using VB2005 and have created a dynamic list of checkboxes and depending on which file the user selects there may be between 1 and 20 checkboxed that appear in a form. The user then checks any number of these checkboxes. I know how many checkboxes exist. I want to scroll down through the check boxes, one after the other and depending on if they are checked or not I different things need to happen. How do I select checkbox 1,...
2
4878
by: scottSD | last post by:
Hi everyone. this is my first post here, but i've found quite a bit of great information from reading the forums in the past. i'm not sure if what i'm trying to do is possible or not, but here it is: i'm creating a dynamic list of checkboxes, basically to allow access to client information on a user by user basis. i use ajax to bring back a full list of clients, then loop through the list and create a checkbox for each client to...
0
1290
by: galien8 | last post by:
Dear Newsgroup Readers, I have a problem with dynamic controls, in a DotNetNuke module, and event handlers in VB.NET ASP.NET 2.0. Events are firing and being handled, sometimes good but also sometimes in a wrong way. I always unchecked the first of the list (See Also Source Code Below): CheckBox1 sender ID = D0 CheckBox2 CheckBox3
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8771
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7371
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4182
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.