Dim conn As OleDbConnection Dim cmd, cm As OleDbDataAdapter conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("exam.mdb")) cmd = New OleDbDataAdapter("select * from exam where type='panduan' ", conn) Dim ds As DataSet = New DataSet cmd.Fill(ds) DataList1.DataSource = ds DataList1.DataBind() conn.Close() 是什么问题?
你是指question字段的数据不全,还是返回的记录数不全?
就是question还有些字段没有显示,条件type='panduan' 是满足的
先检查question字段类型,宽度; 在sql里用select * from exam where type='panduan'测试一下返回值 看看是sql问题还是代码问题
另外,检查一下Label的css样式,看看是不是样式将溢出的字符截掉了
在数据库中测试select * from exam where type='panduan'看返回的结果是怎么样的, 还有在datalist中是不是使用了table固定了表格的话有时候会遮住一些字符。
我用datagrid来显示记录是可以的,然后用datalist的话,就少了一半记录,我也没改变datalist的设置。请问怎么办? 前台代码 <%@ Page Language="vb" AutoEventWireup="false" Codebehind="exam.aspx.vb" Inherits="examnationonline.exam"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>exam</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <table height="76" cellSpacing="1" cellPadding="0" width="760" align="center" border="0"> <tr> <td class="style8" borderColor="#000000" align="center" bgColor="#e2f2ff" height="74"><img height="74" src="file:///G|/EXAM/kaoshi2/images/TOP.jpg" width="753"> </td> </tr> </table> <table height="29" width="760" align="center" bgColor="#ffffff" border="0"> <tr> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">首页</div> </fieldset> </td> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">练习</div> </fieldset> </td> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">考试</div> </fieldset> </td> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">成绩查询</div> </fieldset> </td> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">用户管理</div> </fieldset> </td> <td width="126" bgColor="#afdbff"> <fieldset> <div align="center"><IMG height="14" src="images/more01.gif" width="15">题库管理</div> </fieldset> </td> </tr> </table> <asp:datalist id="DataList1" runat="server"> <SelectedItemTemplate> <FONT face="宋体"></FONT> </SelectedItemTemplate> <ItemTemplate> <asp:Label id="Label1" runat="server" Width="37px" Height="15px"> <%# DataBinder.Eval(Container.DataItem, "id") %> </asp:Label><FONT face="宋体">、 <asp:Label id="Label3" runat="server" Width="469px"> <%# DataBinder.Eval(Container.DataItem, "question") %> </asp:Label></FONT> </ItemTemplate> <AlternatingItemTemplate> <FONT face="宋体"></FONT> </AlternatingItemTemplate> </asp:datalist> </form> </body> </HTML> 后台代码 Imports System.Data.OleDb Public Class exam Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList '注意: 以下占位符声明是 Web 窗体设计器所必需的。 '不要删除或移动它。 Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: 此方法调用是 Web 窗体设计器所必需的 '不要使用代码编辑器修改它。 InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '在此处放置初始化页的用户代码 If Not IsPostBack Then Dim conn As OleDbConnection Dim cmd, cm As OleDbDataAdapter conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("exam.mdb")) cmd = New OleDbDataAdapter("select * from exam where type='panduan' ", conn) Dim ds As DataSet = New DataSet cmd.Fill(ds) DataList1.DataSource = ds DataList1.DataBind()
Dim cmd, cm As OleDbDataAdapter
conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("exam.mdb"))
cmd = New OleDbDataAdapter("select * from exam where type='panduan' ", conn)
Dim ds As DataSet = New DataSet
cmd.Fill(ds)
DataList1.DataSource = ds
DataList1.DataBind()
conn.Close()
是什么问题?
在sql里用select * from exam where type='panduan'测试一下返回值
看看是sql问题还是代码问题
还有在datalist中是不是使用了table固定了表格的话有时候会遮住一些字符。
前台代码
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="exam.aspx.vb" Inherits="examnationonline.exam"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>exam</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table height="76" cellSpacing="1" cellPadding="0" width="760" align="center" border="0">
<tr>
<td class="style8" borderColor="#000000" align="center" bgColor="#e2f2ff" height="74"><img height="74" src="file:///G|/EXAM/kaoshi2/images/TOP.jpg" width="753">
</td>
</tr>
</table>
<table height="29" width="760" align="center" bgColor="#ffffff" border="0">
<tr>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">首页</div>
</fieldset>
</td>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">练习</div>
</fieldset>
</td>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">考试</div>
</fieldset>
</td>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">成绩查询</div>
</fieldset>
</td>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">用户管理</div>
</fieldset>
</td>
<td width="126" bgColor="#afdbff">
<fieldset>
<div align="center"><IMG height="14" src="images/more01.gif" width="15">题库管理</div>
</fieldset>
</td>
</tr>
</table>
<asp:datalist id="DataList1" runat="server">
<SelectedItemTemplate>
<FONT face="宋体"></FONT>
</SelectedItemTemplate>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Width="37px" Height="15px">
<%# DataBinder.Eval(Container.DataItem, "id") %>
</asp:Label><FONT face="宋体">、
<asp:Label id="Label3" runat="server" Width="469px">
<%# DataBinder.Eval(Container.DataItem, "question") %>
</asp:Label></FONT>
</ItemTemplate>
<AlternatingItemTemplate>
<FONT face="宋体"></FONT>
</AlternatingItemTemplate>
</asp:datalist>
</form>
</body>
</HTML>
后台代码
Imports System.Data.OleDb
Public Class exam
Inherits System.Web.UI.Page#Region " Web 窗体设计器生成的代码 " '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList '注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not IsPostBack Then
Dim conn As OleDbConnection
Dim cmd, cm As OleDbDataAdapter
conn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("exam.mdb"))
cmd = New OleDbDataAdapter("select * from exam where type='panduan' ", conn)
Dim ds As DataSet = New DataSet
cmd.Fill(ds)
DataList1.DataSource = ds
DataList1.DataBind()
conn.Close()
End If
End SubEnd Class
<FONT face="宋体"></FONT>
</AlternatingItemTemplate>
===
问题在这里,你设定了交替项,去掉或改成
<AlternatingItemTemplate>
<asp:Label id="Label5" runat="server" Width="37px" Height="15px">
<%# DataBinder.Eval(Container.DataItem, "id") %></asp:Label>
<asp:Label id="Label6" runat="server" Width="469px"><%# DataBinder.Eval(Container.DataItem, "question") %></asp:Label>
</AlternatingItemTemplate>