Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am storing multiple values through a listbox to database column. Now in my column values are like this : 21,34,12,
i have a seperate table for these values like 21 is food, 34 is fuel, 12 is education.
now i want to show these all values on one repeater label seperated by ',' like this food,fuel,education.
Previously i am storing only one value and according to it i am fetching its corresponding value from other table on a label. Code i am using is:
SQL
select r.*, sc.subcategory_name from tbl_adregister r join tbl_subcategory as sc on r.subcategory=sc.subcategory_id

ASP.NET
<asp:Label ID="lbl_subcategory" runat="server" Text='<%#Eval("subcategory_name")%>'></asp:Label>

subcategory column value: 21
Result: Food

Now i want to show like this...
subcategory column value: 21,34,12,
Result: Food,Fuel,Education
Posted
Updated 6-Jun-14 21:57pm
v3
Comments
BulletVictim 5-Jun-14 1:29am    
Seems pretty straight forward. It will require two selects from the database though. First of all select you select back only the column with the ID's(21,34,12) as a string value. Then feed that string value into an Array. Then within a for each on the array you select back the description(Food,Fuel,Education) for the ID and build up a different string value using the result of the select.
Below is an example of how I did this:

shared.CALENDAR_APPOINTMENT_USERS_SEL(e.Appointment.ID, Users);
userArray = Strings.Split(Users, ",");
foreach (void Item_loopVariable in userArray) {
Item = Item_loopVariable;
string emailAddress = string.Empty;
shared.CALENDAR_USER_EMAIL_SEL(Item, emailAddress);
message.To.Add(new MailAddress(emailAddress));
UsersList += Item;
}

with shared being a reference to the class Library I use to connect to my stored procedures, Users being the the first string variable getting its value from an output parameter in my stored procedure, emailAddress also getting its value from an output parameter in my second stored procedure and UserList being the final string variable that will be used to display the desired result.

Please ask if there is something about this you do not understand
Mycroft Holmes 5-Jun-14 2:03am    
Next time when supplying a solution do not add it as a comment, it is difficult to read as there is no formatting, it does not show up as a solution (and others come in to answer it when you have done the job) and you get not rep points for your work.
BulletVictim 5-Jun-14 2:28am    
The reason I add it as a comment is because it might not be the correct answer for the scenario that was stated in the question(as most of the questions on the site is asked by people who's first language is not english and the context of the question is not always clear). If this solution is confirmed by the Raj then I will post it as a solution and it can then be marked as by Raj as the correct answer. Also allowing the question to remain "unanswered" it allows more people to contribute to finding the correct answer and solving the question correctly with multiple options, this also allows people who are experiencing similar problems to find the best solution for their scenario(it might be contained in one of the answers) as it will be faster to search for the correct solution than having to ask the same question over and over(as a lot of people asking for help on the site have already tried searching and could not find the solution for their scenario). Where as if it is marked as having a answer most people will over look it.
And I'm not concerned with rep points, as long as the correct answer is found for the problem.
Raj Negi 7-Jun-14 3:56am    
i want to do it at sql level...

select r.*, s.s_name, c.category_name, sc.subcategory_name,
from tbl_adregister r
INNER JOIN tbl_state s ON r.state = s.s_id join tbl_category as c on r.category=c.category_id
join tbl_subcategory as sc on r.subcategory = sc.subcategory_id
where country='1' and category='1'

here at tbl_subcategory table join r.subcategory has 21,34,12, values
I want to split it by ',' and match with sc.subcategory_id one by one
but dont know how to do it.
BulletVictim 9-Jun-14 11:27am    
http://stackoverflow.com/questions/2647/how-do-i-split-a-string-so-i-can-access-item-x

1 solution

You should re-factor your database and create a proper data structure, not the garbage you have to work with.

Your multi value field should be a many to many link table like:

SQL
LinkID - identity
CategoryID  - 1 of your multi values
ItemID  - the id for the table your multi values reside in 
 
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