我想用datalist显示图片,可是怎么显示不出来呀1.<asp:DataList id="MyDataList" style="Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 160px"
runat="server" RepeatColumns="3" Width="448px" Height="112px">
<ItemTemplate>
<IMG width=100 height=100 alt="" src='<%#DataBinder.Eval(Container,"DataItem.image")%>"'>
<%#DataBinder.Eval(Container.DataItem,"imagename")%>
<%#DataBinder.Eval(Container.DataItem,"imagedate")%>
</ItemTemplate>
</asp:DataList>2.if(!IsPostBack)
{
string conn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection("conn");
// Connect to the SQL database using a SQL SELECT query to get all
// the data from the "Titles" table.
SqlDataAdapter myCommand = new SqlDataAdapter("select top 9 from image order by imagedate", myConnection);
// Create and fill a DataSet.
DataSet ds = new DataSet();
myCommand.Fill(ds);
// Bind MyDataList to the DataSet. MyDataList is the ID for
// the DataList control in the HTML section of the page.
MyDataList.DataSource = ds;
MyDataList.DataBind();
}
runat="server" RepeatColumns="3" Width="448px" Height="112px">
<ItemTemplate>
<IMG width=100 height=100 alt="" src='<%#DataBinder.Eval(Container,"DataItem.image")%>"'>
<%#DataBinder.Eval(Container.DataItem,"imagename")%>
<%#DataBinder.Eval(Container.DataItem,"imagedate")%>
</ItemTemplate>
</asp:DataList>2.if(!IsPostBack)
{
string conn=ConfigurationSettings.AppSettings["dsn"];
SqlConnection myConnection = new SqlConnection("conn");
// Connect to the SQL database using a SQL SELECT query to get all
// the data from the "Titles" table.
SqlDataAdapter myCommand = new SqlDataAdapter("select top 9 from image order by imagedate", myConnection);
// Create and fill a DataSet.
DataSet ds = new DataSet();
myCommand.Fill(ds);
// Bind MyDataList to the DataSet. MyDataList is the ID for
// the DataList control in the HTML section of the page.
MyDataList.DataSource = ds;
MyDataList.DataBind();
}
解决方案 »
- |ZYCWPF| 如要在DataTrigger中去修改ViewModel的MyMessage属性 有示例代码 谢谢
- visual studio replace single line with multiline
- 出差中遇到Bug急求解
- 加密解密时遇到的问题
- 写个Hello World, 理解下IoC DI 不知正确与否, 请各位指教 不胜感激!
- 大家推荐几本C#的视频音频编解码方面的书
- 读取一个unicode的xml文件,保存怎么成了utf-8格式的呢?
- 想学习.net,大家给推荐个培训学校
- 求一个正则表达式
- asp_net老是意外重新启动的问题。救俺一命吧。
- C#如何向Excel中插入图片
- C# 中使用IE控件常有问题,烦死人了。大家救助一下啊
如果你的数据库里面存放的是图片的二进制数据,这个就比起上面的来要复杂一点,你需要一个中间过程,将二进制数据转化为图片.比较典型的就是新建一个输入类型为流的aspx文件,直接从此文件中将二进制数据转化为图片,并输入.而datagrid里面的image控件将显示此图片.
如:datagrid里面的image控件的绑定数据为: image.aspx?id=数据库中图片的编号而image.aspx将根据传递来的ID参数从数据库里获取二进制数据还原成图片将输入流.