0
我想在我的網頁上顯示學生信息和學生圖像,同時從下拉列表中選擇學生ID。下面給出的代碼用於顯示信息和圖像。但圖像顯示不正確。請檢查代碼和輸出屏幕。很熱來顯示二進制圖像從數據庫到圖像框。?8
代碼:
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>
數據的基礎上:
輸出:
非常感謝。不,它工作完美 – Vipin 2014-10-17 08:47:21