我有Grid View
我有2列(评分和星级)。在星列中,我显示了5 imagebuttons
。我想要的是如果评级是1我想只有一个星(图像按钮)是可见的,如果评级是2然后是2个图像按钮,同样到5。
以下是我的图片TemplateField
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
答案 0 :(得分:1)
假设Rating
是一个整数,您可以使用内联代码
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ImageButton" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" Visible='<%# int.Parse(Eval("rating").ToString()) >= 1 ? true : false %>' />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" Visible='<%# int.Parse(Eval("rating").ToString()) >= 2 ? true : false %>' />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" Visible='<%# int.Parse(Eval("rating").ToString()) >= 3 ? true : false %>' />
<asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" Visible='<%# int.Parse(Eval("rating").ToString()) >= 4 ? true : false %>' />
<asp:ImageButton ID="ImageButton4" runat="server" ImageUrl="/eur/Home/OfferLetter/images/delete_icon.gif" CausesValidation="false" Visible='<%# int.Parse(Eval("rating").ToString()) >= 5 ? true : false %>' />
</ItemTemplate>
</asp:TemplateField>