0

Basically I'm writing a program that through a form let's a person Upload an Image of a Tool and later on in another Page is able to View the Tools & Their Information in which one of the Columns is the Image.

Here is the Code I am using to 'Place' the Image in the GridView;

<asp:TemplateField HeaderText="Image">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Image") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Height="100px" Width="100px"
                                ImageUrl='<%#"data:Image/png;base64," + Convert.ToBase64String((byte[])Eval("ImageData")) %>'></asp:Image>
                    </ItemTemplate>
                </asp:TemplateField>

Now I am stuck at how to able to Use the following SQL Command to be able to populate my GridView Column 'Image'.

I tried to look up some Tutorials but most of them have a whole table dedicated to Images and therefore use the Sql Command Select * FROM tblImages and then populate the whole table in a GridView.

In my Case I just want the SQL to Take 1 Column from my Table and Populate it in 1 GridView Column.

   private void LoadImages()
        {
            string cs = ConfigurationManager.ConnectionStrings["ToolsConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("Select Images from Tools",con);
                con.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                GridView1.
            }
        }

Thanks for the Help!

3
  • 1
    Although you can simply assign the datasource property of gridview to rdr and call the DataBind method, it won't work because in aspx you are expecting ImageData column but you are fetching only Images column. What you are storing in your DB? I mean image in binary format or the image path? Commented Feb 20, 2017 at 8:35
  • Image Path, so how do you think this should work best? Commented Feb 20, 2017 at 8:42
  • If you are storing Image Path, just fetch it and assign it to the gridview's datasource. Check this answer as a sample. Commented Feb 20, 2017 at 8:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.