• 从数据库读取图片,并固定显示


    <asp:datagrid id="DG_Persons" Width="168px" HeaderStyle-HorizontalAlign="Center" Runat="server"
                                BorderColor
    ="Black" ItemStyle-BackColor="Beige" HeaderStyle-ForeColor="#ffffff" HeaderStyle-Font-Bold="True"
                                HeaderStyle
    -BackColor="#ff0000" AutoGenerateColumns="False">
                                
    <ItemStyle BackColor="Beige"></ItemStyle>
                                
    <HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="Red"></HeaderStyle>
                                
    <Columns>
                                    
    <asp:TemplateColumn HeaderText="图片">
                                        
    <ItemTemplate>
                                            
    <asp:Image id=Image3 Height="186px" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "imgid")) %>' Width="212px" Runat="server">
                                            </asp:Image>
                                        
    </ItemTemplate>
                                    
    </asp:TemplateColumn>
                                
    </Columns>
                            
    </asp:datagrid>
     Private Sub BindGrid(ByVal id)

            
    Dim strCnn As String = "server=.;database=master1;uid=sa;pwd="

            
    Dim myConnection As SqlConnection = New SqlConnection(strCnn)
            
    Dim dst As New DataSet
            
    Dim sda As SqlDataAdapter
            
    'Dim myCommand As SqlCommand = New SqlCommand("SELECT * FROM image1 where imageid=" & i, myConnection)
            sda = New SqlDataAdapter("SELECT * FROM KS_img where imgID=" & id, myConnection)
            
    'myCommand.CommandType = CommandType.Text
            dst.Clear()
            sda.Fill(dst, 
    "aaa")

            
    Try

                myConnection.Open()
                row 
    = table.NewRow
                
    'row.Item("照片") = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
                row.Item("imgid"= dst.Tables("aaa").Rows(0).Item(0)
                row.Item(
    "Img"= dst.Tables("aaa").Rows(0).Item(1)
                
    'row.Item("PersonImage") = dst.Tables("aaa").Rows(0).Item(2)
                'row.Item("PersonImageType") = dst.Tables("aaa").Rows(0).Item(3)
                table.Rows.Add(row)
                table.GetChanges()

                myConnection.Close()
                
    Me.DG_Persons.DataSource = table
                
    Me.DG_Persons.DataBind()

            
    Catch SQLexc As SqlException

                Response.Write(
    "Error occured while Generating Data. Error is " & SQLexc.ToString())

            
    End Try

        
    End Sub

  • 相关阅读:
    CODEVS4650 破损的键盘
    洛谷P1656 炸铁路
    洛谷 P3225 [HNOI2012]矿场搭建
    1265 四点共面
    1406: [AHOI2007]密码箱
    1193: [HNOI2006]马步距离
    1800: [Ahoi2009]fly 飞行棋
    1923: [Sdoi2010]外星千足虫
    I
    2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)
  • 原文地址:https://www.cnblogs.com/fxf568/p/532944.html
Copyright © 2020-2023  润新知