*显示图片方法为例子

.aspx

<asp:GridView ID="GridView1" runat="server" BackColor="#DEBA84"

  BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"

  CellSpacing="2" AutoGenerateColumns="False" Width="100%">

  <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

  <Columns>

  <asp:TemplateField HeaderText="图片">

      <ItemTemplate>

          <asp:Image ID="img0" runat="server"  Height="100" ImageUrl="images/no_pic.jpg" />                             </ItemTemplate>

     <HeaderStyle Width="150px" />

     <ItemStyle Width="150px" CssClass="gcc" />

  </asp:TemplateField>

</Columns>

<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />

<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

</asp:GridView>

 

.vb

Dim GV_Img_Count As Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If IsPostBack = True Then Exit Sub

        Call Reload()

    End Sub

    Public Sub Reload()

        GV_Img_Count = 0

End Sub

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 

If e.Row.RowType = DataControlRowType.DataRow Then '一定要在

   Dim rowView As DataRowView = CType(e.Row.DataItem, DataRowView)

   Dim imgFile As System.Web.UI.WebControls.Image = CType(e.Row.FindControl("img0"), System.Web.UI.WebControls.Image)

   Dim SQLstr As String

   Dim dTb As DataTable

   SQLstr = "Select YN=Case 状态 when '0' then '使用中' when '1' then '暂停使用' End,* From Table"

   dTb = SqlSelect(SQLstr)

   If dTb.Rows.Count <> 0 Then

       If dTb.Rows(GV_Img_Count).Item("图片位置").ToString <> "" Then

            imgFile.ImageUrl = dTb.Rows(GV_Img_Count).Item("图片位置").ToString

       Else

            imgFile.ImageUrl = "images/no_pic.jpg"

       End If

       GV_Img_Count = GV_Img_Count + 1

   End If

End If

End Sub

相关文章