日期:2014-05-17  浏览次数:20542 次

repeater如何使用IF语句?
后台:
  public string EditLink(string title,string id,string updatetime)
  {
  string linkstring="";
  int newsid = Convert.ToInt16(id);
  if (newsid==3)
  {
  linkstring= "<a href='NoticeDetail.aspx?NewsID=" + newsid + "' target='_blank' title='" + title + "'>&nbsp;&nbsp;&nbsp;&nbsp;>> " + title + "</a>&nbsp;&nbsp;&nbsp;[" + updatetime + "]"; 
  }
  else
  {
  linkstring = "<a href='NewsDetail.aspx?NewsID=" + newsid + "' target='_blank' title='" + title + "'>&nbsp;&nbsp;&nbsp;&nbsp;>> " + title + "</a>&nbsp;&nbsp;&nbsp;[" + updatetime + "]"; 
  }
  }
前台代码:
  <marquee scrollamount="3" scrolldelay="30" direction="left" width="100%" height="15" onmouseover="this.stop();" onmouseout="this.start();" style="margin-top:0px;"> 
  <asp:Repeater ID="rp_Ann" runat="server">
  <ItemTemplate>
  <%# EditLink(Eval("Title").ToString(),Eval("NewsID").ToString(),Eval("UpdateTime", "{0:MM-dd}").ToString() %>
  </ItemTemplate>
  </asp:Repeater>
  </marquee>

运行后出错:CS0161: “ascx_head.EditLink(string, string, string)”: 并非所有的代码路径都返回值
这要怎么处理?

------解决方案--------------------
EditLink方法少了return linkstring;
------解决方案--------------------
public string EditLink(string title,string id,string updatetime)
{
string linkstring="";
int newsid = Convert.ToInt16(id);
if (newsid==3)
{
linkstring= "<a href='NoticeDetail.aspx?NewsID=" + newsid + "' target='_blank' title='" + title + "'>&nbsp;&nbsp;&nbsp;&nbsp;>> " + title + "</a>&nbsp;&nbsp;&nbsp;[" + updatetime + "]";
}
else
{
linkstring = "<a href='NewsDetail.aspx?NewsID=" + newsid + "' target='_blank' title='" + title + "'>&nbsp;&nbsp;&nbsp;&nbsp;>> " + title + "</a>&nbsp;&nbsp;&nbsp;[" + updatetime + "]";
}
return linkstring ;
}
------解决方案--------------------
在后面加上return linkstring;返回个值 供调用的地方使用。