•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,068 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,270 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 9133 | Replies: 2
![]() |
•
•
Join Date: Sep 2005
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
Hello there,
Currently I am working with the project which needs dynamically generated checkboxes and i have generated dynamic checkboxes but i am facing problem with getting the vaue of selected checkboxes.
Problem is described below in detail to easily understood, so please let me know if you come to know...
Example:
I am creating a form to assign rights to site admin for managing different module of the site from back end. Please have a look at attached file to better understand the structure of admin rights form which i used.
I had created checkbox dynamically with below statement FOR EACH Module.
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='A'>Add
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='E'>Edit
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='D'>Delete
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='S'>Search
Say my Module_Id = 12
After form submit I got value with
form.querystring["chk121"]; form.querystring["chk122"];
form.querystring["chk123"];
form.querystring["chk124"];
But I want to use foreach loop for getting the values of each selected checkboxes Because there are more then 50 moudles. so please,let me know how to do this? Main problem is that I don't know how many total checkbox generated dynamically, that is why I have to use foreach or for loop.
Any help, advice or pointers on this matter would be highly appreciated.
Thanks,
Paresh
Currently I am working with the project which needs dynamically generated checkboxes and i have generated dynamic checkboxes but i am facing problem with getting the vaue of selected checkboxes.
Problem is described below in detail to easily understood, so please let me know if you come to know...
Example:
I am creating a form to assign rights to site admin for managing different module of the site from back end. Please have a look at attached file to better understand the structure of admin rights form which i used.
I had created checkbox dynamically with below statement FOR EACH Module.
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='A'>Add
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='E'>Edit
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='D'>Delete
lblCheck.Text += "<input type='checkbox' name='chk[" + daDetail["Module_id"] + i.ToString() + "]' value='S'>Search
Say my Module_Id = 12
After form submit I got value with
form.querystring["chk121"]; form.querystring["chk122"];
form.querystring["chk123"];
form.querystring["chk124"];
But I want to use foreach loop for getting the values of each selected checkboxes Because there are more then 50 moudles. so please,let me know how to do this? Main problem is that I don't know how many total checkbox generated dynamically, that is why I have to use foreach or for loop.
Any help, advice or pointers on this matter would be highly appreciated.
Thanks,
Paresh
•
•
Join Date: Aug 2005
Posts: 32
Reputation:
Rep Power: 4
Solved Threads: 1
Hi,
I am writing some sample code that generate dynamic CheckBoxes on PageLoad and dynamically displays which one has been selected.
The idea is, instead of wating for the user to click a button to get the values why dont we try to get the value as soon as its been checked.
Hope it helps....
I am writing some sample code that generate dynamic CheckBoxes on PageLoad and dynamically displays which one has been selected.
'Declarations
Dim ckb(7) As CheckBox
Dim i As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 0 To 7 Step 1
ckb(i) = New CheckBox
ckb(i).Text = "CheckBox" + i.ToString
ckb(i).AutoPostBack = True
Panel1.Controls.Add(ckb(i))
Next
End Sub
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
For i = 0 To 7 Step 1
If (ckb(i).Checked = True) Then
Response.Output.Write(ckb(i).Text)
End If
Next
End Sub
The idea is, instead of wating for the user to click a button to get the values why dont we try to get the value as soon as its been checked.
Hope it helps....
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- how to get value of all selected checkbox? (ASP.NET)
- Storing dynamic form values in Arrays for display & insert (PHP)
- Restore the properties of dynamic controls during postbacks (ASP.NET)
- counting checkboxes (ASP.NET)
- dropdownlist value doesnt get selected (ASP)
- Urgent.....Dynamic Changes.... (JavaScript / DHTML / AJAX)
Other Threads in the ASP.NET Forum
- Previous Thread: need help - please
- Next Thread: Retrieving Multiple Columns into Dropdown List


Linear Mode