【问题标题】:how to display binary image to image box? [duplicate]如何将二进制图像显示到图像框? [复制]
【发布时间】:2014-12-11 17:45:53
【问题描述】:

从下拉列表中选择学生 ID 时,我必须在我的网页上显示学生姓名和图像。图像以 var 二进制格式存储在 db 上。如何检索图像并在图像框上显示。下面给出的代码仅显示学生的名字和姓氏。如何显示图像?请帮帮我。

代码:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataSet1TableAdapters.TextBoxTableTableAdapter tx;
        tx = new DataSet1TableAdapters.TextBoxTableTableAdapter();
        DataTable dt = new DataTable();
        dt = tx.GetstudData(int.Parse(DropDownList1.SelectedValue));

        foreach (DataRow row in dt.Rows)
        {
            TextBox1.Text = (row["FirstName"].ToString());
            TextBox2.Text = (row["SecondName"].ToString());
        }
    }

SQL 查询:

SELECT FirstName, SecondName, StudentImage FROM TextBoxTable WHERE (Id = @Id)

aspx来源:

<div>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" />
</div>

数据库:

【问题讨论】:

  • 我不想使用通用的 http 处理程序。我想在我的网页上显示图像而不使用通用 http 处理程序。

标签: c# asp.net image varbinary


【解决方案1】:

是的,这很棘手。图像需要在单独的请求中检索,因此您需要创建一个处理程序,例如,它可以根据 Id 返回图像数据。在此页面中,您只需将 ImageUrl 设置为正确的路径即可检索实际的图像数据。

处理程序(实际上可以只是像StudentImage.aspx 之类的页面或其他任何内容)将从数据库中读取二进制数据,设置所需的响应标头,并将数据写入输出,然后就完成了。

【讨论】:

  • 能否请您发布与我上述代码相关的演示代码。
猜你喜欢
  • 1970-01-01
  • 2014-12-12
  • 1970-01-01
  • 1970-01-01
  • 2016-03-04
  • 2014-08-09
  • 1970-01-01
  • 2013-02-01
  • 1970-01-01
相关资源
最近更新 更多