【发布时间】:2014-12-12 15:04:01
【问题描述】:
从下拉列表中选择学生 ID 时,我必须在我的网页上显示学生姓名和图像。图像以 var 二进制格式存储在 db 上。如何检索图像并在图像框上显示。下面给出的代码仅显示学生的名字和姓氏。如何在不使用 http 通用处理程序页面的情况下显示图像?请帮帮我。
代码:
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>
数据库:
【问题讨论】:
-
你不能。至少你不能轻易。有一种在网页中嵌入图像的方法:websiteoptimization.com/speed/tweak/inline-images,但编写您不想编写的处理程序会变得非常容易。如果您使用的是 MVC 和 WebAPI,那就更容易了。
-
@IanMercer:好的。那么如何为上述代码添加通用 http 处理程序。我想通过从下拉列表中选择 id 来显示图像。您能否发布此代码的示例代码。