Solved

Dynamic checkboxlist, how to assign an ID to a listitem

Posted on 2003-10-28
3
495 Views
Last Modified: 2012-05-04
Hi

Is there a way to change the ID of a listitem in a checkboxlist. with the following code, when I look at the source HTML asp.net
generates its own ID's for the checkboxes.. and I havent found a way to assign an own ID to the checkbox listitems...
Another thing is when I create a listitem (text and value).. when I look at the source html, the Values are not present for the checkbox..

I need the values and the ID's to be retrieved from the form when submitting the form...


-BEGIN CODE-
Dim checkbnew As New CheckBoxList
dim f_tekst as string
dim f_value as string

f_tekst = "text of the checkbox"
f_value = "value of the checkbox"

Dim lstitem As New ListItem(f_tekst, f_value)                        
checkbnew.Items.Add(lstitem)
-END CODE-
0
Comment
Question by:Siliconimage
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
malharone earned 250 total points
ID: 9635440
Private Sub Page_Load(ByVal sender As System.Object, ByValue As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then

Dim objListItem As New ListItem("joe", "millionaire")
Dim objListItem2 As New ListItem("regis", "philbin")
CheckBoxList1.Items.Clear()
CheckBoxList1.Items.Add(objListItem)
CheckBoxList1.Items.Add(objListItem2)
End If
end sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Response.Write
(CheckBoxList1.SelectedItem.Value.ToString)
End Sub

------------------------

or you can just add your own objects. and you should also use multi-select list box
e.g.
public class Student
 
  public overrides function toString() as string
    return fname_ & " " & lname_
  end function

  private fname_,lname_ as string
  public id_ as long

  public sub new(fname as string, lname as string, id as long)
     fname_=fname
     lname_=lname
     id_=id
  end sub
end class

in your form ...

mylistbox.items.add(new Student("Joe","Millionaire",1000000))
mylistbox.items.add(new Student("Regis","Philben",2000000))
..

dim x as integer
dim temp as Student
for x=0 to mylistbox.Items.Count-1
   if mycheckboxlist.Items(x).Selected then
      temp=ctype(mycheckboxlist.Items(x),student)
      ' temp.id_  <===== this is your student id for the selected item
   end if
next
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10232167
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: malharone {http:#9635440}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question