【问题标题】:How to load image into a repeater control from sql server?如何从 sql server 将图像加载到中继器控件中?
【发布时间】:2014-04-19 02:42:55
【问题描述】:

如何从 sql server 的 sql 数据库将图像加载到 A Image 控件中? 图像以图像格式存储... 图像控制在中继器中 中继器中的代码

<table id="tableposts" style="text-align: center; width: 100%; height: 80%;">
    <tr>
        <td>
            <asp:LinkButton ID="lbpostusername" runat="server" 
                Text='<%#Eval("UserName") %>'>
            </asp:LinkButton>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label ID="posthead" runat="server" 
                Text='<%#Eval("PostHead") %>'></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            <p id="postcontent"><%#Eval("PostContent") %></p>
        </td>
    </tr>
    <tr>
        <td>
            <asp:Image ID="postimage" runat="server" ImageUrl=""/>
        </td>
    </tr>
</table>

检索值的代码

private DataSet GetData()
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LoginConString"].ConnectionString);
    SqlDataAdapter da = new SqlDataAdapter("Select PostID,UserName,PostHead,PostContent,PostImage from Posts WHERE USERID ='" + Session["New"].ToString() + "'", con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    postids = ds.Tables[0].Rows[0].ToString();
    return ds;
}

【问题讨论】:

标签: c# sql ado.net


【解决方案1】:

试试这个

public string GetImageFromByte(object byt)
 {
   byte[] byts = (byte[])byt;
   return byteArrayToImage(byts);
 }

代替

   public string GetImageFromByte(object byt)
      {
         byte[] byts = Convert.ToByte(byt);
         return byteArrayToImage(byts);
      }

【讨论】:

  • 不会抛出postimage在当前上下文中不存在的错误
猜你喜欢
  • 2020-11-25
  • 2013-11-15
  • 1970-01-01
  • 1970-01-01
  • 2011-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多