< 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() 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 转载于:https://www.cnblogs.com/fxf568/archive/2006/10/18/532944.html