郁闷了一天的问题结果还有问题(我承认自己很SB)

gundamtw 2008-10-09 06:05:34
我是用VS2005+access做留言板的那个 用的是 <asp:Repeater><ItemTemplate><table>......../ItemTemplate></asp:Repeater>
这样的 另外留言和回复是2个表 sql语句是2表关联查询:string sql = "select a.[Name] as AName,a.[Title],a.[Content] as AContent,a.[Publishdate],a.[ImageURL],b.[Name] as BName,b.[Content] as BContent,b.[Returndate] from Mes a left join Reply b on a.ID=b.MesID
页面代码:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>

<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="height:32px;width:100px; background-color:Blue; text-align:left">
发帖者:<%# Eval("AName")%>
</td>
<td style="height:32px; width:400px; background-color:White; text-align:left">

标题:<%# Eval("Title")%>
</td>
</tr>
<tr>
<td style="height:150px; width:100px; background-color:White; text-align:center">
<asp:Image ID="Image1" runat="server" ImageUrl="~/behindimages/pic1.gif" />
</td>
<td style="height:32px; width:400px; background-color:Green; text-align:center;" rowspan="2">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="height:32px; width:400px; background-color:Fuchsia; text-align:left">
内容:<%# Eval("AContent")%>
</td>
</tr>
</table>

<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td style="height:32px; width:400px; background-color:Transparent; text-align:left">
回复人:<%# Eval("BName")%>
</td>
<td style="height:32px; width:400px; background-color:Transparent; text-align:left">
回复时间:<%# Eval("Returndate")%>
</td>

</tr>
<tr>
<td style="height:32px; width:400px; background-color:Transparent; text-align:left" colspan="2">
回复内容:<%# Eval("BContent")%>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td style="height:32px; width:100px; background-color:Red; text-align:left">
发帖时间:<%# Eval("Publishdate")%>
</td>
<td></td>
</tr>
</table>

</ItemTemplate>
</asp:Repeater>

基本的现在可以显出来了 不过问题又来了 这样不能像Gridview一样自己分页 全部显示到一列了 而且还有个问题是留言头像怎么让他绑定我查询出来的图片路径 还有就是留言如果没回复就显示暂无回复 而不是还继续这样显示出回复人、回复时间还都是空的 拜托各路高手来指点一下 小的感激涕零~ 不能在线= 要明天才上了 能解决的希望大家帮忙下
路过的也帮忙Up一下啊 谢谢了
...全文
84 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
888228 2008-10-09
  • 打赏
  • 举报
回复
再给个事例吧




public class Text_Info : Sql.AccDB
{
/// <summary>
/// 数据列表
/// </summary>
public DataTable List(out int result)
{
srcTblName = "tmp"; //临时表名,随意
StartIn = 1; //取数起始
EndSize = 100; //取多少条

result = 0;
strSQL = Sql.SqlUtil.Text_Info.SqlStr_List; //SQL语句
ReturnDt(); //执行

//计算数据总数并返回
strSQL = Sql.SqlUtil.Text_Info.SqlStr_List_Count; //数据集总数
srcTblName = "";
ReturnDt();
if(dtReturn.Rows.Count>0)
result = (int)dtReturn.Rows[0][0];
return dsReturn.Tables[0]; //返回数据集
}


}

庚武讲堂 2008-10-09
  • 打赏
  • 举报
回复
如果需要分页的话,建议使用DataList控件,DataList可以设置水平或垂直排列。还可以设置每行或每列大小。

可以自己写个分页的控件,比较复杂。
888228 2008-10-09
  • 打赏
  • 举报
回复

using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web.UI;

namespace Sql
{
/// <summary>
/// Access数据操作底类
/// </summary>
public class AccDB
{

OleDbConnection oleConn = null;

DataTable dt;
DataSet ds;
string Ers;
int resultInt;

string ConString = "DB";//web.config中相应数据库连接字符串.

string strsql = "";
int Start = 0;
int MaxSize = 0;
string TblName = "";
string Properties="";
string strPath;

protected void Run()
{
using(oleConn = oleConns())
{
try
{
oleConn.Open();
//执行
OleDbCommand cmd = new OleDbCommand(strsql ,oleConn);
resultInt = cmd.ExecuteNonQuery();
cmd.Dispose();
}
catch(Exception ex)
{
Ers = ex.Message.ToString();
#if DEBUG
throw new InvalidOperationException("DEBUG SQL执行出错:"+strsql+"\\n"+ex.Message.ToString());
#else
Log.CShowError.ShowError("SQL执行出错:"+strsql+"\\n"+ex.Message.ToString());
#endif
}
finally
{
oleConn.Close();
oleConn.Dispose();
}
}
}

public void ReturnDt()
{
using(oleConn = oleConns())
{
try
{
oleConn.Open();
//查询
OleDbDataAdapter myDapter = new OleDbDataAdapter(strsql ,oleConn);

if(TblName=="")
{
dt = new DataTable();
resultInt = myDapter.Fill(dt);
}
else
{
ds = new DataSet();
resultInt = myDapter.Fill(ds,Start,MaxSize,TblName);
}

}
catch(Exception ex)
{
Ers = ex.Message.ToString();
#if DEBUG
throw new InvalidOperationException("DEBUG SQL执行出错:"+strsql+"\\n"+ex.Message.ToString());
#else
Log.CShowError.ShowError("SQL执行出错:"+strsql+"\\n"+ex.Message.ToString());
#endif
}
finally
{
oleConn.Close();
oleConn.Dispose();
}
}
}

private string Paths()
{
System.Web.UI.Page p = new System.Web.UI.Page();
return p.Server.MapPath(ConfigurationSettings.AppSettings[ConString]);
}

private OleDbConnection oleConns()
{
if(strPath==null)
strPath = Paths();
return new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+strPath+";"+Properties);
}


#region 提供外部访问域成员并设置属性

#region 只读属性域成员
/// <summary>
/// 返回数据集DataTable [只读]
/// </summary>
public DataTable dtReturn
{
get
{
return dt;
}
}

/// <summary>
/// 返回分页数据集DataSet [只读]
/// </summary>
public DataSet dsReturn
{
get
{
return ds;
}
}

/// <summary>
/// 返回错误信息 [只读]
/// </summary>
public string strErs
{
get
{
return Ers;
}
}

/// <summary>
/// 返回操作结果集数 [只读]
/// </summary>
public int result
{
get
{
return resultInt;
}
}
#endregion

#region 只写属性域成员
/// <summary>
/// 数据库联接文件 [只写]
/// </summary>
public string ConnString
{
set
{
ConString = value;
}
}

/// <summary>
/// SQL执行语句 [只写]
/// </summary>
public string strSQL
{
set
{
strsql = value;
}
}

/// <summary>
/// 分页参数:起始数 [只写]
/// </summary>
public int StartIn
{
set
{
Start = value;
}
}

/// <summary>
/// 分页参数:结束数 [只写]
/// </summary>
public int EndSize
{
set
{
MaxSize = value;
}
}

/// <summary>
/// 驱动格式,默认为MDB文件驱动。
/// 如果要驱动ExCle文件,请载入 Extended Properties=Excel 8.0;
/// </summary>
public string strProperties
{
set
{
Properties = value;
}
}

/// <summary>
/// 文件路径,如果不传则按照WebConFig中ConString默认配置来走
/// 如果传入文件路径参数则严格按照传入路径来读取
/// </summary>
public string strFilePath
{
set
{
strPath = value;
}
}
#endregion

#region 读写属性域成员
/// <summary>
/// 分页参数: DataSet 临时表名 [读写]
/// </summary>
public string srcTblName
{
get
{
return TblName;
}
set
{
TblName = value;
}
}
#endregion

#endregion

}
}




带分页功能的access提取类,希望对你有用
gundamtw 2008-10-09
  • 打赏
  • 举报
回复
补充一下 access的那个分页的 我也不会写 希望大家能帮忙 谢谢各位
  • 打赏
  • 举报
回复
不能分页你就写个存储过程啊

62,046

社区成员

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

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

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

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