问题描述
<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventWireup="true"CodeFile="gift.aspx.cs"Inherits="gift"%><%@ImportNamespace="System.Data"%><%@ImportNamespace="System.Data.OleDb"%><asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server"><scriptlanguage="C#"runat="server">voidPage_Load(){datalist1.DataSource=CreateDataView();datalist1.DataBind();}publicDataViewCreateDataView(){stringstrconn="DataSource=LYT-PC\SQLEXPRESS;Password=merry;UserID=lyt;InitialCatalog=christmas";stringstrsql="select*fromgiftList";DataSetds=newDataSet();OleDbConnectionmyconn=newOleDbConnection(strconn);OleDbDataAdaptermyadp=newOleDbDataAdapter(strsql,myconn);myadp.Fill(ds,"giftList");DataViewdv=ds.Tables["giftList"].DefaultView;returndv;}</script></asp:Content><asp:ContentID="Content2"ContentPlaceHolderID="ContentPlaceHolder1"Runat="Server"><asp:datalistID="datalist1"runat="server"RepeatColumns="2"RepeatDirection="Horizontal"Width="560px"ShowHeader="false"ShowFooter="false"Height="294px"><ItemTemplate><fontface="宋体"><tableid="table3"cellspacing="0"cellpadding="0"width="350"height="160"><tr><tdwidth="8"></td><tdvalign="center"align="middle"width="100"><imgstyle="WIDTH:100px;HEIGHT:120px"height="34"src="<%#DataBinder.Eval(Container.DataItem,"giftPicture")%>"align="left"border="0"></a></td><tdwidth="200"><tableid="table4"cellspacing="0"cellpadding="0"width="100%"border="0"height="100"><tr><tdwidth="100%"><spanstyle="DISPLAY:inherit;WIDTH:100%;"><b>名称:</b><%#DataBinder.Eval(Container.DataItem,"giftName")%></span></td></tr><tr><tdwidth="100%"><spanstyle="DISPLAY:inherit;WIDTH:100%;"><b>价钱:</b><%#DataBinder.Eval(Container.DataItem,"giftPrice")%></span></td></tr><tr><tdwidth="100%"><spanstyle="DISPLAY:inherit;WIDTH:100%;"><b>详细信息:</b><%#DataBinder.Eval(Container.DataItem,"Introduce")%></span></td></tr></table></font></ItemTemplate></asp:datalist></asp:Content>
解决方案
解决方案二:
跟踪下你的ds.Tables["giftList"]有数据没?
解决方案三:
你的myconn没有Open
解决方案四:
引用1楼starfd的回复:
跟踪下你的ds.Tables["giftList"]有数据没?
ds.Tables["giftList"]是空的,可是数据库表中是有数据的,怎么办
解决方案五:
DataSetds=newDataSet();OleDbConnectionmyconn=newOleDbConnection(strconn);OleDbDataAdaptermyadp=newOleDbDataAdapter(strsql,myconn);myadp.Fill(ds,"giftList");Conn没有open的情况下,执行Adapter不异常?
解决方案六:
myconn.open()还是什么都没有显示,页面也没有报错
解决方案七:
首先conncet对象先Open,然后检查下你的查询语句是否正确。另外PageLoad事件中的绑定要放在IsPostBack里面!!如voidPage_Load(){if(!IsPostBack){datalist1.DataSource=CreateDataView();datalist1.DataBind();}}
解决方案八:
引用6楼cxzzwb的回复:
首先conncet对象先Open,然后检查下你的查询语句是否正确。另外PageLoad事件中的绑定要放在IsPostBack里面!!如voidPage_Load(){if(!IsPostBack){datalist1.DataSource=CreateDataView();datalist1.DataBind();}}
按照你薯片的方法都改了,还是不行voidPage_Load(){if(!IsPostBack){datalist1.DataSource=CreateDataView();datalist1.DataBind();}}publicDataViewCreateDataView(){stringstrconn="DataSource=LYT-PC\SQLEXPRESS;Password=merry;UserID=lyt;InitialCatalog=christmas";stringstrsql="select*fromgiftList";DataSetds=newDataSet();OleDbConnectionmyconn=newOleDbConnection(strconn);OleDbDataAdaptermyadp=newOleDbDataAdapter(strsql,myconn);myconn.Open();myadp.Fill(ds,"giftList");DataViewdv=ds.Tables["giftList"].DefaultView;returndv;}