Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Can't get selected value from list box...

Can't get selected value from list box...

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Can't get selected value from list box...

Hi, Guys

I got another problem on how to get selected value from listbox... I have a list box which displays subject names from a table. I want to get the id from the table for the subject name...

Here's my code in the get subject listing button
Code:
    DASubject.Fill(DsEduMgnt.SUBJECT)
    With lstbox
            .DataSource = DsEduMgnt.SUBJECT
            .DataTextField = "Subj_NM"
            .DataValueField = "Subj_ID"
            .DataBind()
        End With
I had try to use --> [ lstbox.Items(index).value ] to get the Subj_ID but what i get is Subj_NM .....


Do you know how to get it???

Last edited by Nico; 12-16-06 at 03:15 PM. Reason: Please use [code] wrappers when posting code.
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Guest
 
Posts: n/a
lstbox.selectedvalue, if i remember correctly
Reply With Quote
  #3 (permalink)  
Old
Newbie Coder
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
But when i use lstbox.selectvalue it return nothing....After, i see my coding one more time i realize that i forget to tell u that i have 2 listboxes which can moving item from one to another.

Here's my code in the get subject listing button (first listbox)

DASubject.Fill(DsEduMgnt.SUBJECT)
With lstbox1
.DataSource = DsEduMgnt.SUBJECT
.DataTextField = "Subj_NM"
.DataValueField = "Subj_ID"
.DataBind()
End With

After i moving the items in 1st listbox to 2nd listbox. I need to get the Subj_ID for second listbox...

here my code in the add to database button (2nd listbox)

For i = 0 To lstbox2.Items.Count - 1

Debug.Write(lstbox2.Items(i).Value)

Next

but the result return for me is the subj_NM and not the subj_ID....
Reply With Quote
  #4 (permalink)  
Old
Guest
 
Posts: n/a
in thr for loop you posted replace the .items(i) with

.SelectedItems(i).Value
Reply With Quote
  #5 (permalink)  
Old
Newbie Coder
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
hi, koncept

Did u mean like this?
If like this wil cause an error occur which is Listbox cannot be indexed because it has no default property.

For i = 0 To lstbox2.Items.Count - 1

Debug.Write(lstbox2.SelectedItem(i).Value)

Next

If u mean below the for loop will cause an error occur also which is SelectedItems not a member of listbox

For i = 0 To lstbox2.Items.Count - 1

Debug.Write(lstbox2.SelectedItems(i).Value)

Next
Reply With Quote
  #6 (permalink)  
Old
Guest
 
Posts: n/a
then im not sure...I have never used that control because i have never needed it and i never wanted users to beable to choose more than one item.
Reply With Quote
  #7 (permalink)  
Old
Newbie Coder
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Hi, Koncept

Anyways...I know u had try your best to help ..
Thanks...
Reply With Quote
  #8 (permalink)  
Old
New Member
 
Join Date: Sep 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow solution

Egypt Development Blog | Get value of checked item in CheckedListBox

after bind CheckedListBox with data you can get value of checked items


Code:
For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
                    Dim XDRV As DataRowView = CType(CheckedListBox1.CheckedItems(i), DataRowView)
                    Dim XDR As DataRow = XDRV.Row
                    Dim XDisplayMember As String = XDR(CheckedListBox1.DisplayMember).ToString()
                    Dim XValueMember As String = XDR(CheckedListBox1.ValueMember).ToString()
                    MsgBox("DisplayMember : " & XDisplayMember & "   - ValueMember : " & XValueMember )
Next

now you can use the value or Display of checked items in CheckedListBox from the 2 variable XDisplayMember And XValueMember in the loop


hope to be useful ,,,
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
list box...please help banurekhap@hotmail.com PHP 1 08-11-04 01:33 AM
display selected value in drop down list angela JavaScript 1 04-02-04 09:43 AM
Execute javascript function based on selected dropdown list value. TKOEHN5751 JavaScript 2 03-14-04 01:13 AM


All times are GMT -5. The time now is 08:29 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.