什么是正确的方式来绑定的SqlDataSource到ASP:标签在asp.net 4.0?绑定、正确、标签、方式

2023-09-06 08:31:41 作者:南山相送

是否有可能使用eval?如果是的话,可以有人张贴简短片段来说明?我的SqlDataSource返回1纪录3场,我想这些格式化成一个字符串。例如:

Is it possible using Eval? If so, can someone post a short fragment to illustrate? My SqlDataSource returns 1 record with 3 fields, I'd like to Format these into a string. eg:

记录   现场'名称'='杰克'   现场金额= 100   现场'日期'= 2010年2月12日

Record Field 'Name' = 'Jack' Field 'Amount' = 100 Field 'Date' = 12.02.2010

ASP:标签文本应最终被:

asp:Label text should end up being:

欢迎杰克,最后一次付款是100 2010年2月12号

Welcome Jack, last payment was 100 on 12.02.2010

如果另一个控制比ASP:标签是适当的,那将是一件好事也知道

if another control than asp:Label is appropriate, that would be good to know also.

推荐答案

标签的右侧控制你想要的东西来显示,但SqlDataSource的可能是不正确的控制获取数据。标签没有DataSourceID属性,可以让你联想到一起的控制 - 而你也许可以做一些管道在服务器端code,使其工作,我怀疑是不是会更有效地获取相关的DataRow在Page_Load期间,建立了字符串,然后将其写入标签的Text属性。

Label's the right control for what you want to display, but SqlDataSource probably isn't the right control for getting the data. Labels have no DataSourceID property that allows you associate the controls together - whilst you might be able to do some plumbing in your server-side code to make it work, my suspicion is it'd be more efficient to get the relevant DataRow during Page_Load, build the string and then put that into the Text property of the Label.