Click to See Complete Forum and Search --> : [RESOLVED] Display corresponding details from database when Listbox item is selected


remya1000
09-17-2007, 09:39 AM
i'm using VB.NET.

i have a table names "EMP". this table contain employee details like Index, empID, First name, Last name, address, phone number etc.

while page loads, i need to display Last name First name of all employees in a listbox. and if i select any employee name from listbox and press "EDIT" button, then i need to display the employee details for that particular employee what we selected in listbox.

right now what i did is like when an emp is selected in listbox, i will check the last name and first name in database and display details. but if two employees were there having same first name and last name, then error will occurs and the corresponding employees detail won't be displayed. but i need only first name and last name in listbox.

in that table Index and EMPID were non Dupicated numbers. so any way is there to give index for each employee name in listbox and when an employee name is selected, then according to that index search in database and get corresponding employee details.

if any one have any idea how to do this please let me know. and if you can provide an example then that will be great help for me.

thanks in advance.

lmf232s
09-17-2007, 10:15 AM
Yes you can do exaclty that.
The listbox has 2 properties that you can set:
DataTextField - This is what is displayed
DataValueField - This is the value that is associated with that item

So basically set First and Last name in the DataTextField and then set the ID in the DataValueField.

When you get the value get the value of the DataValueField and not the DataTextField which is what your currently doing.

Hope that helps.

remya1000
09-19-2007, 04:19 PM
once again thanks for this help too...

now i can seperate DataTextField and DataValueField and take corresponding data from table.

thanks a lot...