0

I have to display student name and image on my web page while selecting student id from the drop down list. The image is stored in var binary format on db. How can I retrieve the image and display on image box. The given below code is only shows the student first name and last name. How can I display the image? Please help me.

Code:

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 Query:

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

Aspx Source:

<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>

Data Base:

enter image description here

Vipin
  • 261
  • 6
  • 20
  • 44
  • I don't want to use generic http handler. I want display image on my web page without using generic http handler. – Vipin Oct 16 '14 at 13:35

1 Answers1

2

Yup, that's tricky. Images need to be retrieved in a separate request, so you need to make a handler that can return you the image data based on the Id, for example. In this page, you then just set the ImageUrl to the proper path to retrieve the actual image data.

The handler (which can really be just a page like StudentImage.aspx or whatever) will read the binary data from the database, set the required response headers, and write the data to output, and you're done.

Luaan
  • 62,244
  • 7
  • 97
  • 116