1.后台代码,通过手写方法,得到投票所占百分比:
public int FormatVoteCount(String voteCount, string voteTotal)
{
if (voteCount.Length <= 0 || voteTotal.Length <= 0)
{
return (0);
}
int nVoteTotal = Int32.Parse(voteTotal);
if (nVoteTotal > 0)
{
return ((Int32.Parse(voteCount) * 100 / nVoteTotal));
}
return (0);
}
public int FormatVoteImage(int voteCount)
{
return (voteCount * 3);
}
2.gridview里面绑定的,并且调用方法:
<ItemTemplate>
<asp:Image ID="voteImage" Runat="server" Height="20"
ImageUrl="~/images/Votes.png"
Width='<%# FormatVoteImage(FormatVoteCount
(DataBinder.Eval(Container.DataItem,"VoteCount").ToString(),DataBinder.Eval
(Container.DataItem,"SumVoteCount").ToString()))%>' />
<%# FormatVoteCount(DataBinder.Eval(Container.DataItem,
"VoteCount").ToString(), DataBinder.Eval(Container.DataItem, "SumVoteCount").ToString())%>%
</ItemTemplate>