这里是数据库连接代码..只是一个简单的DataList绑定..
string conn = ConfigurationSettings.AppSettings["conn"];
string comm = "Select * From [dbo].[BooksIntro]";
SqlConnection objConn = new SqlConnection(conn);
SqlDataAdapter objSqlAdapter = new SqlDataAdapter(comm,conn);
DataSet ds = new DataSet();
objSqlAdapter.Fill(ds," [dbo].[BooksIntro]");
this.BooksDataList.DataSource = ds;
this.BooksDataList.DataBind();这里是将数据库中图片的地址绑定到一行中..
<asp:DataList ID="BooksDataList" Runat="server" >
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<img src="<%# DataBinder.Eval(Container.DataItem,"ImgURL")%>"
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>现在问题是,我数据库中的ImgURL字段中,不止一条记录..这样绑定的话..
会将所有的图片都显示出来..
而现在我只想显示一张图书..该用什么方法?
string conn = ConfigurationSettings.AppSettings["conn"];
string comm = "Select * From [dbo].[BooksIntro]";
SqlConnection objConn = new SqlConnection(conn);
SqlDataAdapter objSqlAdapter = new SqlDataAdapter(comm,conn);
DataSet ds = new DataSet();
objSqlAdapter.Fill(ds," [dbo].[BooksIntro]");
this.BooksDataList.DataSource = ds;
this.BooksDataList.DataBind();这里是将数据库中图片的地址绑定到一行中..
<asp:DataList ID="BooksDataList" Runat="server" >
<ItemTemplate>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<img src="<%# DataBinder.Eval(Container.DataItem,"ImgURL")%>"
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>现在问题是,我数据库中的ImgURL字段中,不止一条记录..这样绑定的话..
会将所有的图片都显示出来..
而现在我只想显示一张图书..该用什么方法?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货