后置代码中的计算方法
public int FormatVoteCount(string VOTE_NUMBER, string VOTE_REMARK)
{
if (VOTE_NUMBER.Length <= 0 || VOTE_REMARK.Length <= 0)
{
return (0);
}
int nVOTE_REMARK = Int32.Parse(VOTE_REMARK);
if (nVOTE_REMARK > 0)
{
return ((Int32.Parse(VOTE_NUMBER) * 100 / nVOTE_REMARK));
}
return (0);
}
前置代码中的数据绑定
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%">
<Columns>
<asp:TemplateField HeaderText="题号">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"VOTEID")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="百分比">
<ItemTemplate>
<asp:Image ID="Image1" Width='<%#FormatVoteCount(DataBinder.Eval(Container.DataItem,"VOTE_NUMBER").ToString(),"100") %>' runat="server" ImageUrl="~/Images/vote.gif" /><%#FormatVoteCount(DataBinder.Eval(Container.DataItem,"VOTE_NUMBER").ToString(),"100")%>%
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="总票数">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"VOTE_REMARK")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
public int FormatVoteCount(string VOTE_NUMBER, string VOTE_REMARK)
{
if (VOTE_NUMBER.Length <= 0 || VOTE_REMARK.Length <= 0)
{
return (0);
}
int nVOTE_REMARK = Int32.Parse(VOTE_REMARK);
if (nVOTE_REMARK > 0)
{
return ((Int32.Parse(VOTE_NUMBER) * 100 / nVOTE_REMARK));
}
return (0);
}
前置代码中的数据绑定
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%">
<Columns>
<asp:TemplateField HeaderText="题号">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"VOTEID")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="百分比">
<ItemTemplate>
<asp:Image ID="Image1" Width='<%#FormatVoteCount(DataBinder.Eval(Container.DataItem,"VOTE_NUMBER").ToString(),"100") %>' runat="server" ImageUrl="~/Images/vote.gif" /><%#FormatVoteCount(DataBinder.Eval(Container.DataItem,"VOTE_NUMBER").ToString(),"100")%>%
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="总票数">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"VOTE_REMARK")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>