DataList 怎么显示从数据库读取并绑定的二进制数据?

btbtd 2007-03-02 01:00:31
从表中读取数据, 然后 绑定 到 DataList
其中有一个字段是 长二进制 数据类型,
怎么在 DataList 中显示吗?

下面的方法不行... 只显示: System.Byte[]
<div class="text">
<%# DataBinder.Eval(Container.DataItem, "content") %>
</div>

详细:
<%@ Page Language="C#" AutoEventWireup="True" validateRequest="false" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<%@ import Namespace="System.Web.UI.WebControls" %>
<%@ Assembly src="cs/Pagination.cs" %>
<%@ Reference Control="ac/sqEditor.ascx" %>
<%@ Reference Control="ac/sqEditor.ascx" %>
<script runat="server">

public string EdRoot = "/sqEditor_DotNet/";
public string ReqIdStr = HttpContext.Current.Request.QueryString["id"];
public string ReqAidStr = HttpContext.Current.Request.QueryString["aid"];

void Page_Load(Object s, EventArgs e)
{
string SqlCnnStr;
SqlCnnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+
@MapPath(EdRoot+"/data/shawlqiu.mdb");

string SqlQuery;
SqlQuery = "select * from shawlqiu_";

switch(ReqIdStr)
{
case "edit":
GetEditor("<b>hello</b>, test this.", edPlaceHolder, EdRoot+"ac/sqEditor.ascx");
break;

case "display":
SqlQuery+=" where articleid = "+ReqAidStr;
DisplayList(SqlQuery, SqlCnnStr, acDisplayAtDataList);
break;

default:
DisplayList(SqlQuery, SqlCnnStr, acDataList);
break;
}

} // end Page_Load

private void DisplayList(string SqlQuery, string SqlCnnStr, DataList acDataList)
{
Pagination Paged=new Pagination();
Paged.Debug=false; // 是否为调试模式
Paged.DebugLabel=acDebugLabel; // 显示调试信息的 Label
Paged.NavigatorLabel=acPagedLabel; // 显示主导航条的 Label
Paged.DetailsLabel=acPagedDetailsLabel;// 显示分页明细的 Label
Paged.PageSize=20; // 每页大小
Paged.Go(GetDataTable(SqlQuery, SqlCnnStr), acDataList); // 执行分页
Paged=null;
}

private DataTable GetDataTable(string qry, string cnn, string tableName)
{
DataSet ds = new DataSet();
OleDbConnection oCnn = new OleDbConnection(cnn);
OleDbDataAdapter oDa;

oDa = new OleDbDataAdapter(qry, cnn);
oDa.Fill(ds, tableName);
oCnn.Close();
return ds.Tables[tableName];
} // end private void GetData

private DataTable GetDataTable(string qry, string cnn)
{
return GetDataTable(qry, cnn, "dt");
} // end private void GetData

public void GetEditor(string inti, PlaceHolder edPlaceHolder, string edPath)
{
sqEditor ed = (sqEditor)LoadControl(edPath);
ed.EdRoot = EdRoot;
ed.EdIntiText = inti;
ed.SubmitEventHandler = new EventHandler(Submit);

edPlaceHolder.Controls.Add(ed);
}

public void Submit(Object s, EventArgs e)
{
TextBox edTextBox =
(TextBox)((Button)s).Parent.FindControl("edTextBox");

HtmlGenericControl edIntiDiv =
(HtmlGenericControl)((Button)s).Parent.FindControl("edIntiDiv");

edIntiDiv.InnerHtml = edTextBox.Text;

if(edTextBox == null) return;

acDebugLabel.Text = edTextBox.Text;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/*<![CDATA[*/
@import "<% Response.Write(EdRoot); %>style/style.css";
/*]]>*/
</style>
</head>
<body>
<div class="Main">
<form runat="server">
<asp:Label id=acDebugLabel runat=server
/>
<div class="algc">
<div class="pagedList">
<asp:Label id=acPagedLabel runat=server
/>
</div>
<div class="pagedDetails">
<asp:Label id=acPagedDetailsLabel runat=server
/>
</div>
</div>
<div class="acMain">
<asp:DataList id="acDisplayAtDataList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Flow"
RepeatColumns="10"
ShowBorder="True"
runat="server">

<HeaderTemplate>
<ol class="acOlList">
</HeaderTemplate>

<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>

<AlternatingItemStyle>
</AlternatingItemStyle>

<ItemTemplate>
<li>
<span class="algr fltr">
<a href="?id=edit&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>">
edit
</a>
</span>
<a href="?id=display&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>">
<%# DataBinder.Eval(Container.DataItem, "title") %>
</a>
<div class="text">
<%# DataBinder.Eval(Container.DataItem, "content") %>
</div>
</li>
</ItemTemplate>
<%--
<SeparatorTemplate>
</SeparatorTemplate>
--%>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:DataList>
<asp:DataList id="acDataList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Flow"
RepeatColumns="10"
ShowBorder="True"
runat="server">

<HeaderTemplate>
<ol class="acOlList">
</HeaderTemplate>

<HeaderStyle BackColor="#aaaadd">
</HeaderStyle>

<AlternatingItemStyle>
</AlternatingItemStyle>

<ItemTemplate>
<li>
<span class="algr fltr">
<a href="?id=edit&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>">
edit
</a>
</span>
<a href="?id=display&aid=<%# DataBinder.Eval(Container.DataItem, "articleid") %>">
<%# DataBinder.Eval(Container.DataItem, "title") %>
</a>
</li>
</ItemTemplate>
<%--
<SeparatorTemplate>
</SeparatorTemplate>
--%>
<FooterTemplate>
</ol>
</FooterTemplate>
</asp:DataList>
</div>

<div class="sqEditorDiv">
<asp:PlaceHolder id=edPlaceHolder runat=server
/>
</div>
</form>
</div>
<p/><a href="?">--back--</a>
</body>
</html>
...全文
329 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
btbtd 2007-03-02
  • 打赏
  • 举报
回复

查了 MSDN, 貌似 <%# %> 与 模板化控件只能输出字符串,

找了个替代方法:
DataTable dt = (DataTable)ds.Tables[tableName];
DataRow dr = dt.Rows[0];

byte[] bytCnt = (byte[])dr["content"];
System.Text.Encoding encoding = System.Text.Encoding.Unicode;

HttpContext.Current.Response.Write(
encoding.GetString(bytCnt)
btbtd 2007-03-02
  • 打赏
  • 举报
回复
不是图片信息, 是 长二进制文本,
haidazi 2007-03-02
  • 打赏
  • 举报
回复
是图片信息吗?
fengyeng 2007-03-02
  • 打赏
  • 举报
回复
tolong
up
btbtd 2007-03-02
  • 打赏
  • 举报
回复
晕了...就没人来指点一下...
不过还是完美解决掉了.
<div class="text">
<%#
System.Text.Encoding.Unicode.GetString(
(byte[])DataBinder.Eval(Container.DataItem, "content")
)
%>
</div>

62,046

社区成员

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

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

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

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