我在书上看到下面一段代码,是关于用类似进度条来显示百分比的,但我没有运行成功,不知问题出在哪里?书上也没有给出FormatVoteImage()函数,试了很多都没有成功,哪位高手能帮我指点指点,谢谢了!<asp:DataGrid ID="VoteList" runat="server" AutoGenerateColumns="False"
DataKeyField="VoteID" BackColor="White" BorderColor="White" BorderStyle="Ridge"
BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="SqlDataSource1"
GridLines="None" style="font-size: small" PageSize="35" >
<Columns>
<asp:TemplateColumn HeaderText ="所占总票数的百分比">
<ItemStyle Width ="300px" ></ItemStyle>
<ItemTemplate>
<asp:Image ID ="VoteImage" runat ="server" Height ="20" Width='<%# FormatVoteImage(FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").Tostring())) %>' ImageUrl="../images/Vote.gif"></asp:Image>
<%# FormatVoteCount (DataBinder.Eval(Container .DataItem ,"VoteCount")) %>%
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>其中FormatVoteCount()函数是这样的:
public int FormatVoteCount(string VoteCount)
{
//如果没有投票
if (VoteCount.Length <= 0)
{
//返回0个百分比
return (0);
}
if (VoteTotal >0)
{
//返回实际百分比
return ((Int32.Parse(VoteCount) * 100 / VoteTotal));
}
return (0);
}
DataKeyField="VoteID" BackColor="White" BorderColor="White" BorderStyle="Ridge"
BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="SqlDataSource1"
GridLines="None" style="font-size: small" PageSize="35" >
<Columns>
<asp:TemplateColumn HeaderText ="所占总票数的百分比">
<ItemStyle Width ="300px" ></ItemStyle>
<ItemTemplate>
<asp:Image ID ="VoteImage" runat ="server" Height ="20" Width='<%# FormatVoteImage(FormatVoteCount(DataBinder.Eval(Container.DataItem,"VoteCount").Tostring())) %>' ImageUrl="../images/Vote.gif"></asp:Image>
<%# FormatVoteCount (DataBinder.Eval(Container .DataItem ,"VoteCount")) %>%
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>其中FormatVoteCount()函数是这样的:
public int FormatVoteCount(string VoteCount)
{
//如果没有投票
if (VoteCount.Length <= 0)
{
//返回0个百分比
return (0);
}
if (VoteTotal >0)
{
//返回实际百分比
return ((Int32.Parse(VoteCount) * 100 / VoteTotal));
}
return (0);
}
你看的是这个?
public int FormatVoteCount(String voteCount)
{ //如果投票没有被投票
if(voteCount.Length <= 0)
{ //返回0个百分比
return(0);
}
if(voteTotal > 0)
{ //返回实际的百分比
return((Int32.Parse(voteCount)* 100/voteTotal));
}
return(0);
}public int FormatVoteImage(int voteCount)
{ //返回百分比的图像的长度
return(voteCount * 3);
}
CS1061: “object”不包含“Tostring”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Tostring”(是否缺少 using 指令或程序集引用?)