显示标签的多个列值 [英] show multiple column value to label

查看:74
本文介绍了显示标签的多个列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过列表框将多个值存储到数据库列。现在我的列值是这样的:21,34,12,

i有一个单独的表,这些值如21是食物,34是燃料,12是教育。

现在我想在一个转发器标签上显示这些所有值,分别用','像这样的食物,燃料,教育。

以前我只存储一个值,根据它,我正在取其相应的来自标签上其他表的值。我正在使用的代码是:

 选择 r。*,sc.subcategory_name 来自 tbl_adregister r  join  tbl_subcategory  as  sc  on  r.subcategory = sc.subcategory_id 



 <   asp:标签    ID   =  lbl_subcategory    runat   =  server   文本  ='  <% #Eval(  subcategory_name)%>' >   <   / asp:Label  >  



子类别列值:21

结果:食物



现在我想要这样展示......

子类别列值:21,34,12,

结果:食物,燃料,教育

解决方案

你应该重新开始 - 影响你的数据库并创建一个合适的数据结构,而不是你必须使用的垃圾。



你的多值字段应该是多对多的链接表,如:



 LinkID  -  身份 
CategoryID - 1 您的多
ItemID - 您的多驻留


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:

select r.*, sc.subcategory_name from tbl_adregister r join tbl_subcategory as sc on r.subcategory=sc.subcategory_id


<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

解决方案

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:

LinkID - identity
CategoryID  - 1 of your multi values
ItemID  - the id for the table your multi values reside in 


这篇关于显示标签的多个列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆