Click here to Skip to main content
15,902,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In DropDown i want to pass the multiple Value fields . How to pass

Ex:
Job Code (PK)     Item Code (PK)   Item 
1                      1            A
1                      2            B
1                      3            c
2                      1            D
2                      2            c


ddl.TextField="Item"
ddl.Valuefield="...."

Please help me to solve this issue...
Posted
Comments
vivektiwari97701 29-Oct-12 8:25am    
first of All Normalize Your DataBase ......bcoz That's Best way ...
[no name] 29-Oct-12 8:29am    
could u please explain briefly why bcz i'm fresher now only i learn all the points
vivektiwari97701 29-Oct-12 8:40am    
ok
According To Your Ex. Your Itemcode Shoud Be PK(Primary Key Field ) And Job code Is FK(Foreign Key )
Like This

JobCode(FK) ItemCode(PK) Item
1 1 A
1 2 B
1 3 c
2 4 D
2 5 c


And Then If U Want To Bind Your Item With Drop Down List You Can use

ddl.TextField="Item1"
ddl.Valuefield="ItemCode"

and If U want To View Item Code and Item Name in DDl then just Cahnge Your SQL Command To

select JobCode,ItemCode,Item+'-'+ItemCode as Item1 from tblItem

But if Your Item Code Would Be Not Unique Then You Will face Lot Of Problem And Bad Method In terms Of DataBase Technique .

 
Share this answer
 
Comments
[no name] 29-Oct-12 8:40am    
Sry TR ,

I want to pass multiple value fields . U give me some information in that links they use single column as value field but i want to pass multiple columns as value field
__TR__ 29-Oct-12 8:51am    
You can concatenate the 2 columns into 1 columns and then pass the concatenated column.
SELECT [Job Code] + '-' + [Item Code] AS Code, Item FROM YourTable
[no name] 29-Oct-12 8:53am    
k i try like that but on here i have a small doubt when i try to concatinate the columns , i'm facing some problem what ever i concate the columns that columns datatype is different . ex job_code datatype is varchar and itemcode datatype is int, what should i do
__TR__ 29-Oct-12 9:14am    
Use CAST or CONVERT[^] to convert int to varchar.
Ex: SELECT CAST([JOB CODE] AS VARCHAR) + '-' + CAST([Item Code] AS VARCHAR)
[no name] 29-Oct-12 9:16am    
YAH superb it's working fine thanks alot
There is no way to do this.. you can have following option.
select / merge two column values into a single with separating with special character while retriving from database and then assing that column value as value field in dropdown.

e.g.

select (Job Code + ';' + Item Code) as Code,Item from Table.

set valueField='Code';
set textfield = 'Item';

while retring dropdown selected value, just split with ';'.

Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900