Hi in my table i have a field which would store the file path of an image, the datatype is a varchar, and i wrote the following filepath in it but it didnt work, when i tried to call it up in the browser it didnt show, is the way i saved it below the right format?
C:\Millio\Documents\Project\Images\car.jpg
That's fine, but you will have to post some of your code so we can see why it might not be diplaying.
|||Hi thanks for responding this is the part where i am calling the image from;
<ItemTemplate>
<span><spanstyle="font-size: 14pt">
<asp:ImageID="Image1"ImageUrl='<%# Eval("Images") %>'runat="server"/>
<br/>
|||
You should store the virtual path of your image in the database rather than the physical path.
If you use a physical path like the one you are showing, you will need to use an HttpHandler to stream the image to the browser. The img tag takes a url value for the src attribute, so you could move the images to a folder within your web site, and reference them with a virtual path. Or if Project is already your virtual directory (the root folder for your web site), the path that you should store in the database is "images/car.jpg" or "~/images/car.jpg". Both will work, but the second one is ASP.NET specific, and can only be used when setting the ImageURL property of an asp server control. I would opt for the first one, just in case I decided to convert the site to PHP.
Or more realistically, decide to use the value to build up the src attribute of an <img> tag in code, and don't bother with a server control.
Hi Mike the reason i did it that way is because i am using a user control to load up my pages, and i didnt want to have to make a page for each category, i will show you what i mean;
<%@.ControlLanguage="C#"AutoEventWireup="true"CodeFile="CategoryList.ascx.cs"Inherits="CategoryList" %>
<scriptrunat="server">
string _Category = "washing machines";
public string Category
{
get { return _Category; }
set { _Category = value; }
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label ID = (Label)DataList1.SelectedItem.FindControl("categoryIDLabel");
// Label AD = (Label)DataList1.SelectedItem.FindControl("PriceLabel");
Label MD = (Label)DataList1.SelectedItem.FindControl("categoryNameLabel");
Trace.Write("category " + ID.Text);
//Trace.Write("Price " + AD.Text);
Trace.Write("categoryName " + MD.Text);
Session["scategoryID"] = ID.Text;
//Session["scategorydescription"] = AD.Text;
Session["scategoryName"] = MD.Text;
}
protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource1.SelectParameters["categoryName"].DefaultValue = _Category;
}
</script><asp:DataListID="DataList1"runat="server"BackColor="White"BorderColor="Transparent"
BorderStyle="None"BorderWidth="1px"CellPadding="4"DataSourceID="SqlDataSource1"
ForeColor="Black"GridLines="Horizontal"OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
<FooterStyleBackColor="#CCCC99"ForeColor="Black"/>
<SelectedItemStyleBackColor="White"Font-Bold="True"ForeColor="White"Font-Italic="False"Font-Overline="False"Font-Strikeout="False"Font-Underline="False"/>
<HeaderStyleBackColor="#333333"Font-Bold="True"ForeColor="White"/>
<SeparatorStyleBackColor="Black"BorderColor="Black"BorderStyle="Solid"BorderWidth="2px"/>
<AlternatingItemStyleBackColor="White"Font-Bold="False"Font-Italic="False"Font-Overline="False"
Font-Strikeout="False"Font-Underline="False"/>
<ItemTemplate>
<span><spanstyle="font-size: 14pt">
<asp:ImageID="Image1"ImageUrl='<%# Eval("categoryImage") %>'runat="server"/>
<br/>
<asp:LabelID="categoryNameLabel"runat="server"Text='<%# Eval("categoryName") %>'ForeColor="DimGray"Font-Size="11pt"Font-Names="Trebuchet MS"></asp:Label><br/>
<br/>
<spanstyle="color: black"></span>
<asp:LabelID="CategoryIDLabel"runat="server"Visible="False"Text='<%# Eval("categoryID") %>'ForeColor="DimGray"Font-Size="11pt"></asp:Label><br/>
<br/>
<asp:LabelID="categoryDescriptionLabel"runat="server"Visible="True"Text='<%# Eval("categoryDescription") %>'ForeColor="DimGray"Font-Size="11pt"></asp:Label><br/>
<br/>
<br/>
</ItemTemplate></asp:DataList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:streamConnectionString %>"
SelectCommand="SELECT [categoryID], [categoryImage], [categoryName], [categoryDescription] FROM [Categories] WHERE ([categoryName] = @.categoryName)">
<SelectParameters>
<asp:ParameterName="categoryName"Type="string"/>
</SelectParameters></asp:SqlDataSource>
No comments:
Post a Comment