日期:2014-05-20  浏览次数:20377 次

图片显示链接,image类型
如题,数据库中是image类型,在aspx用什么控件将来显示出来,并且还可以用于链接?

------解决方案--------------------
ImageButton
------解决方案--------------------
这个取决于你的Image中到底存放的是什么内容,如果是图片,网上从数据库读取图片的资料很多,如果是声音视频的话,要用其他的方法!
------解决方案--------------------
SqlConnection con = new SqlConnection(constr.getCon());
con.Open();
SqlCommand cmd = new SqlCommand( "insert into organ.organ values(@name ,@photo) ", con);
cmd.Parameters.AddWithValue( "@name ", name);
//操作图片
Stream ms;
byte[] picbyte = null;
try
{
if ((ms = this.openFileDialog1.OpenFile()) != null)
{
//MessageBox.Show( "ok ");
picbyte = new byte[ms.Length];
ms.Position = 0;
ms.Read(picbyte, 0, Convert.ToInt32(ms.Length));

}
}
catch { picbyte=new byte[10];}

cmd.Parameters.AddWithValue( "@photo ", picbyte);


if (cmd.ExecuteNonQuery() == 1)
result = true;
con.Close();
------解决方案--------------------
不知道你在数据库里保存的图片,是以什么方式保存的。如果是以路径保存的话,只的直接读就可以了,用dataset直接读就可以了
------解决方案--------------------
<%@ Page Language= "vb " Debug= "true " %>
<%@ Import Namespace= "System.Data " %>
<%@ Import Namespace= "System.Data.OleDb " %>
<script language= "VB " runat= "server ">
dim MyConnection As OleDbConnection

Sub Page_Load(s As Object, E As EventArgs)
MyConnection = New OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " + Server.MapPath( ". ")+ "/db/kk.mdb ")
If Not (IsPostBack) then
BindDataGrid()
End If
End Sub

Sub BindDataGrid()
dim dadTitles as OleDbDataAdapter
dim dstTitles as DataSet
dadTitles=new OleDbDataAdapter( "select * from [imgs] order by id desc ",MyConnection)
dstTitles=new DataSet
dadTitles.fill(dstTitles)
MyDataGrid.DataSource=dstTitles
MyDataGrid.DataBind()
End Sub

Sub Mydatagrid_PageIndexChanged(s as object,e as DataGridPageChangedEventargs)
MyDataGrid.CurrentPageIndex=e.newPageIndex
BindDataGrid()
End Sub

Function FormatURL(strArgument) as String
Return ( "RetrieveImgByDataGrid_SelectImg.aspx?id= " & strArgument)
End Function

</script>
<html>
<head> <title> DataGrid_CheckBox.aspx </title> </head>
<body>
<B> <A HREF= "insertimgtodatabase.aspx "> Insert Img To DataBase </A> </B>
<form runat= "server ">
<asp:DataGrid id= "MyDataGrid "
width= "300 "
Runat= "server "
AllowPaging= "true "
pageSize= "5 "
OnPageIndexChanged= "Mydatagrid_PageIndexChanged "
cellPadding= "3 "
AutoGenerateColumns= "false "
HeaderStyle-BackColor= "#ff0000 "