1
我正在使用gridview在页面上显示信息。条件是,当我从数据库结果获得Y赠我需要绑定/images/goldx.png
否则/images/check.gif
我该怎么办,我现在用asp.net与vb.net作为后端在Gridview中绑定图像
<asp:GridView ID="grdLocation" runat="server" Width="100%" AutoGenerateColumns="false" >
<Columns>
<asp:TemplateField HeaderText="Monthly" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblLotName" runat="server" Text='<%#Eval("is_monthly") %>'></asp:Label>
<asp:Image ID="resultImage" runat="server" ImageUrl='<%# Eval("is_monthly") == 'Y' ? "~/Images/check.gif" : "~/Images/goldx.png" %>' />
</ItemTemplate>
</asp:TemplateField>
<Columns>
</asp:GridView>
我绑定GridView的代码:
Protected Function bindLocations()
Try
Dim _ds As DataSet
If _locComp Is Nothing Then
_locComp = New LocationComponent()
End If
_ds = _locComp.GetAllLots()
If _ds.Tables(0).Rows.Count > 0 Then
grdLocation.DataSource = _ds
grdLocation.DataBind()
End If
Catch ex As Exception
End Try
End Function
感谢您的意见和解答。
其实我不知道VB,但我认为你必须使用gridview的rowdatabound事件,你可以从数据库中捕获Y并在图像控件中使用适当的图像。 –