Hi
I'm trying to learn c# but from a classic asp background, I get very confused (easily)
I am trying to fetch and dispay an image. All I need from the database is the productid the rest of the url will be hard coded like this
"
http://www.example.com/" + <%# MyProductid %> + ".jpg"
<asp:Image ID="Image1" runat="server" Width="200" Height="200" ImageUrl='<%# "
http://www.example.com/" + <%# MyProductid %> + ".jpg" %>' />
but that does not work.
it does work for things like title
<title><%= MyTitle %></title>
my data looks like this
public partial class _Default : System.Web.UI.Page
{
private string myTitle;
protected string MyTitle
{
get { return myTitle; }
set { myTitle = value; }
}
private string myHeading;
protected string MyHeading
{
get { return myHeading; }
set { myHeading = value; }
}
private string myProductinfo;
protected string MyProductinfo
{
get { return myProductinfo; }
set { myProductinfo = value; }
}
private string myProductid;
protected string MyProductid
{
get { return myProductid; }
set { myProductid = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
String ConnStr = "";
String SQL = "SELECT a.productname,a.productid,b.description,a.tag,a.modelnumber FROM table a join be_posts b on a.productid = b.productid WHERE a.productid ='20130'";
SqlDataAdapter TitlesAdpt = new SqlDataAdapter(SQL, ConnStr);
DataSet Titles = new DataSet();
TitlesAdpt.Fill(Titles);
DataRow dr = Titles.Tables[0].Rows[0];
dr["productname"].ToString();
MyTitle = dr["productname"].ToString();
myHeading = dr["productname"].ToString();
myProductinfo = dr["description"].ToString();
myProductid = dr["productid"].ToString();
}
}
Open in new window
please can someone show me an example of how to do this properly?
Open in new window
Does changing it to the below help?
Open in new window