【发布时间】:2014-02-27 09:22:18
【问题描述】:
我正在使用 gridview 在页面上显示信息。条件是当我从数据库结果中得到 Y 时,我需要绑定 /images/goldx.png Else /images/check.gif 我该怎么做我使用 asp.net 和 vb.net 作为后端
<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并在图像控件中使用适当的图像。
标签: asp.net vb.net visual-studio-2010