I have this ASP.NET code:
<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None">
<Columns>
<asp:ImageField DataImageUrlField="image" >
</asp:ImageField>
<asp:BoundField DataField="imagename" />
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString);
SqlCommand command = new SqlCommand("SELECT * from [Image]", connection);
SqlDataAdapter ada = new SqlDataAdapter(command);
ada.Fill(dt);
gvImages.DataSource = dt;
gvImages.DataBind();
}
Here in datatable, I have imagename and image as columns containing values
blue F:\R&D\RD\RD\Images\nextlabel.gif
red F:\R&D\RD\RD\Images\fDSC03578.JPG
green F:\R&D\RD\RD\Images\fDSC03556.JPG
Under this directory I have the images too.
I get the image name in the grid but the image is not getting displayed.
This is an easy thing to do, but still I am not able to achieve it.
Where am I going wrong?
it is not wise to hold absolute path of images in your table..because it is bound to your current file system…in your image url fields you should have just name of a image…
so…
copy your images from your local disk to your server dir, for example your_app/images/
change your images url’s in your table to names of images, for example:
nextlabel.gif
change your markup of gridview to be:
hope this helps