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!

Satwik Nadkarny
  • 5,086
  • 2
  • 23
  • 41
  • 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? – Rahul Singh Feb 20 '17 at 08:35
  • Image Path, so how do you think this should work best? – Bendan Schembri Feb 20 '17 at 08:42
  • If you are storing Image Path, just fetch it and assign it to the gridview's `datasource`. Check [this answer](http://stackoverflow.com/a/16381518/1529657) as a sample. – Rahul Singh Feb 20 '17 at 08:44

0 Answers0