在DataList里面怎么判断一个值??急急!在线等待

fslhj 2003-03-11 10:48:04
如:
<asp:DataList id="DataList1" runat="server"
RepeatDirection="Horizontal"
RepeatColumns="2">
<ItemTemplate>
<%# Container.DataItem("content")%>
<br>
</ItemTemplate>
</ASP:Datalist>

我想当字段“content”的值为“no”时显示“发表”
当该值不为“no”时显示<%# Container.DataItem("content")%>

该怎么作判断呢?
请高手指点

在线......
...全文
92 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jmsofts 2003-04-10
  • 打赏
  • 举报
回复
gz
fslhj 2003-03-11
  • 打赏
  • 举报
回复
问题已解决:
将上面的
public sub tocontent(content as object)
Dim strcontent as string= content.ToString()
if (strcontent = "no") then
content="[提供]"
else
content=strcontent
end if
end sub

改成:
function tocontent(content as object)
Dim strcontent as string= content.ToString()
if (strcontent = "no") then
content="[提供]"
else
content=strcontent
end if
end function
即可

非常感谢谢各位
fslhj 2003-03-11
  • 打赏
  • 举报
回复
saucer(思归, MS .NET MVP) 的方法可行,
不过好象在“VB”在行不通。
如:
<script language="VB" runat=server>

public sub tocontent(content as object)
Dim strcontent as string= content.ToString()
if (strcontent = "no") then
content="[提供]"
else
content=strcontent
end if
end sub
</script>

<asp:DataList id="DataList1" runat="server"
RepeatDirection="Horizontal"
RepeatColumns="2">
<ItemTemplate>
<%# tocontent(Container.DataItem("content"))%><br>
</ItemTemplate>
</ASP:Datalist>

错误:
E:\master\fm1949.com\music\music\index1.aspx(302) : error BC30518: Overload resolution failed because no accessible 'ToString' can be called with these arguments:
'Public Shared Overloads Function ToString(value As String) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Date) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Decimal) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Double) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Single) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As System.UInt64) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Long) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As System.UInt32) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Integer) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As System.UInt16) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Short) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Byte) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As System.SByte) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Char) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Boolean) As String': Expression does not produce a value.
'Public Shared Overloads Function ToString(value As Object) As String': Expression does not produce a value.

target.SetDataBoundString(8, System.Convert.ToString(tocontent(Container.DataItem("content"))))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dragontt 2003-03-11
  • 打赏
  • 举报
回复
不好意思,楼上的各位
我没看思归老大的回答
5555555555555
dragontt 2003-03-11
  • 打赏
  • 举报
回复
呵呵
我很佩服我自己呢
这样写就可以了
<%# (((Container.DataItem("content")=="no")?"发表":Container.DataItem("content")).ToString()%>
dragontt 2003-03-11
  • 打赏
  • 举报
回复
这是数据绑定的介绍

当在 ASP.NET 页上调用 DataBind 方法时,数据绑定表达式在该页上的任何属性(包括服务器控件属性)和数据源之间创建绑定。可以将数据绑定表达式包含在服务器控件开始标记中属性/值对的值侧,或页中的任何位置。

<tagprefix:tagname property="<%# data-binding expression %> runat="server" />


literal text <%# data-binding expression %>


要达到你的要求,只有一个办法,再绑定之前将数据处理一次
因为<%# data-binding expression %>中不支持写表达式

如果有更好的方法,欢迎指教
:)
kinglht 2003-03-11
  • 打赏
  • 举报
回复
同意楼上!!
saucer 2003-03-11
  • 打赏
  • 举报
回复
add a method

string GetValue (object o)
{
if (o == null || o == DBNull.Value)
return "";

if (o.ToString().ToLower() == "no")
return "发表";

return o.ToString();
}


<%# GetValue(Container.DataItem("content"))%>


or

<%# Container.DataItem("content").ToString().ToLower() == "no" ? "发表" : Container.DataItem("content").ToString() %>
garth 2003-03-11
  • 打赏
  • 举报
回复
可以阿,用摸板列什么不能放阿
garth 2003-03-11
  • 打赏
  • 举报
回复
可以在itemdatabind事件中判断("content")的值
然后用label控件显示相应的值
fslhj 2003-03-11
  • 打赏
  • 举报
回复
而且需要读取的数据是多行,label是不能存在于DataList控件里面的
fslhj 2003-03-11
  • 打赏
  • 举报
回复
这里涉及到一个分页问题,这样做很不方便呀。
OK521 2003-03-11
  • 打赏
  • 举报
回复
在这里用label控件来代替,在后台程序中用datareader来判断

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧