我希望在我的网页上显示学生信息和学生形象,同时从下拉列表中选择学生ID。下面给出的代码用于显示信息和图像。但图像显示不正确。请检查代码和输出屏幕。
代码:
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());
byte[] barrImg = (byte[])row["StudImage"];
string base6=Convert.ToBase64String(barrImg);
Image1.ImageUrl = "data:image/jpeg;base6," + base6;
}
}
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>
数据库:
输出:
答案 0 :(得分:1)
base64而不是base6 ???
Image1.ImageUrl = "data:image/jpeg;base64," + base6;