DA

JOANAOAFDAO 2006-05-17 12:11:09
我用SELECT WHERE 语句选择表里的数据,然后再绑定到datalist的LABEL里<%# DataBinder.Eval(Container.DataItem, "question") %>,怎么显示的数据少了一半?怎么解决?
...全文
211 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
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()
是什么问题?
webwait 2006-05-17
  • 打赏
  • 举报
回复
代码看看
wangsaokui 2006-05-17
  • 打赏
  • 举报
回复
代码帖出来看看
wangsaokui 2006-05-17
  • 打赏
  • 举报
回复
怎么显示的数据少了一半?

datalist中是否做了设置
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
我用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()

conn.Close()

End If
End Sub

End Class
stone3_hl 2006-05-17
  • 打赏
  • 举报
回复
前台的代码也发出来吧,看来问题出在前台。
flamelp 2006-05-17
  • 打赏
  • 举报
回复
在数据库中测试select * from exam where type='panduan'看返回的结果是怎么样的,
还有在datalist中是不是使用了table固定了表格的话有时候会遮住一些字符。
webwait 2006-05-17
  • 打赏
  • 举报
回复
另外,检查一下Label的css样式,看看是不是样式将溢出的字符截掉了
webwait 2006-05-17
  • 打赏
  • 举报
回复
先检查question字段类型,宽度;
在sql里用select * from exam where type='panduan'测试一下返回值
看看是sql问题还是代码问题
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
我怎么给你分,点TOP吗
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
谢谢楼上这位朋友,已经可以了!
webwait 2006-05-17
  • 打赏
  • 举报
回复
<AlternatingItemTemplate>
<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>
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
RepeatColumns改了也没用的,哪位高手知道到底怎么解决啊?为什么DATAGRID可以读出全部10记录,而DATALIST却只有1、3、5、7、9五条?
JOANAOAFDAO 2006-05-17
  • 打赏
  • 举报
回复
就是question还有些字段没有显示,条件type='panduan' 是满足的
nayc 2006-05-17
  • 打赏
  • 举报
回复
将 DataList 控件的 RepeatColumns 属性设置为所需的列数
webwait 2006-05-17
  • 打赏
  • 举报
回复
你是指question字段的数据不全,还是返回的记录数不全?

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧