基于.NET的网络投票

  在网络投票系统中,其中的投票也就是在数据库中的一个字段更新,加1,这些没有什么特别的,其中最让我着迷的是其中百分比以图形显示,也就是数据转换。

  通的<asp:image>控件,改变控件的width属性也实现图形的显示。

代码如下:

前台:

<asp:Image ID="voteImage" height="20" runat="server" width='<%# FormatVoteImage(FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").ToString()))%></asp:Image>

后台主要是两个函数一个是FormatVoteImage另一个是FormatVoteCount代码如下:

public int FormatVoteCount(String voteCount)

{

  if(voteCount.Length<=0)

  {

    return(0);

  }

  if(voteTotal>0)

  {

    return(Int32.Parse(voteCount)*100/voteTal));

  }

  return(0);

}

public int FormatVoteImage(int voteCount)

{

  return(voteCount*3);

}

posted @ 2011-01-22 11:14  我是一根葱  阅读(393)  评论(0)    收藏  举报