473,382 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 userSelectionList, Ulist2 As
System.Web.UI.WebControls.CheckBoxList
Protected WithEvents checkboxcontainer As PlaceHolder

For i = 0
Dim selectedItem As New ListItem(appstring, appstring)
'selectedItem.Selected = True
userselectionlist.Items.Add(selectedItem)
Next i

checkboxcontainer.Controls.Add(userselectionlist)

etc..
td1.Controls.Add(checkboxcontainer)
tr1.Controls.Add(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:TableCell ID='appname' Visible=true ColumnSpan="1"
HorizontalAlign="Right">
<br>
<asp:Literal id="mySelections" Runat="server"></asp:Literal>
<asp:PlaceHolder ID="checkboxcontainer" Runat="server" />
<asp:CheckBoxList 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 userSelectionList As New CheckBoxList
userSelectionList = CType(form1.FindControl("mylist"), CheckBoxList)
Ulist2 = CType(form1.FindControl("mylist"), CheckBoxList)
Try
For x = 0 To Ulist2.Items.Count - 1
If Ulist2.Items(x).Selected = True Then
results.Text += Ulist2.Items(x).Value
'mySelections.Text += userSelectionList.Items(x).Value

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 - checkboxcontainer.

My page init looks something like:

InitializeComponent()
If Not IsPostBack Then
buildform(sender, e)
Else

'userSelectionList = New CheckBoxList
'checkboxcontainer = New PlaceHolder
'userSelectionList = CType(form1.FindControl("mylist"),
CheckBoxList)
'checkboxcontainer.Controls.Add(userSelectionList)
'checkcontainer()
buildform(sender, e)
apppb()

End If

Can someone get this scenario to work?

Regards;

tjt:
Nov 19 '05 #1
1 2548
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 userSelectionList, Ulist2 As
System.Web.UI.WebControls.CheckBoxList
Protected WithEvents checkboxcontainer As PlaceHolder

For i = 0
Dim selectedItem As New ListItem(appstring, appstring)
'selectedItem.Selected = True
userselectionlist.Items.Add(selectedItem)
Next i

checkboxcontainer.Controls.Add(userselectionlist)

etc..
td1.Controls.Add(checkboxcontainer)
tr1.Controls.Add(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:TableCell ID='appname' Visible=true ColumnSpan="1"
HorizontalAlign="Right">
<br>
<asp:Literal id="mySelections" Runat="server"></asp:Literal>
<asp:PlaceHolder ID="checkboxcontainer" Runat="server" />
<asp:CheckBoxList 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 userSelectionList As New CheckBoxList
userSelectionList = CType(form1.FindControl("mylist"), CheckBoxList)
Ulist2 = CType(form1.FindControl("mylist"), CheckBoxList)
Try
For x = 0 To Ulist2.Items.Count - 1
If Ulist2.Items(x).Selected = True Then
results.Text += Ulist2.Items(x).Value
'mySelections.Text += userSelectionList.Items(x).Value

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 - checkboxcontainer.

My page init looks something like:

InitializeComponent()
If Not IsPostBack Then
buildform(sender, e)
Else

'userSelectionList = New CheckBoxList
'checkboxcontainer = New PlaceHolder
'userSelectionList = CType(form1.FindControl("mylist"),
CheckBoxList)
'checkboxcontainer.Controls.Add(userSelectionList)
'checkcontainer()
buildform(sender, 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
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:...
0
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...
3
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...
4
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...
4
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...
2
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,...
0
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...
2
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...
0
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.