2009-10-12 51 views
0

前端条件我有一个数据网格,在网格其作出这一呼吁:(C#)在数据网格

<ItemTemplate>          
<%#GroupSelectorRoleListControlExtender.GenerateGroupActuator(((GroupListItem)Container.DataItem).Id, ((GroupListItem)Container.DataItem).Name)%> 
</ItemTemplate> 

我愿做这样的事情:

<% if (((SingleAccountGroup)Container.DataItem).Name == "blahblah") {%> 
<ItemTemplate> 
<%#GroupSelectorRoleListControlExtender.GenerateGroupActuator(((SingleAccountGroup)Container.DataItem).Id, ((SingleAccountGroup)Container.DataItem).Name, "portalprofile Name")%> 
</ItemTemplate> 
<%} %> 

它当然不起作用,但希望你能看到我想要做什么,它不喜欢它没有约束。我怎样才能把这个条件放到这样的数据网格中?

回答

1

你也许可以使用三元运算符,使其工作

<%# 

((SingleAccountGroup)Container.DataItem).Name == "blahblah" ? 
GroupSelectorRoleListControlExtender.GenerateGroupActuator(((SingleAccountGroup)Container.DataItem).Id, ((SingleAccountGroup)Container.DataItem).Name, "portalprofile Name") : "" 

%> 
+0

它的工作,但它提出的空白处对于不等于等等等等的那些...非常接近,虽然我想。 – Brandon 2009-10-12 18:36:02

+0

如果你不想要“空白点”,你将不得不在别的东西后面有东西。一个三元运算符读起来像(条件)? (IfTrue):(IfFalse)。在John的例子中,你会注意到“IfFalse”的返回值只是空字符串。如果你把其他东西放在那里,你会变得金黄。 – 2009-10-12 18:53:28

+0

啊,好的。这就说得通了!谢谢! – Brandon 2009-10-12 19:20:19