image display problem in table

Posted by Klbaiju under Regular Expressions on 6/23/2011 | Points: 10 | Views : 1895 | Status : [Member] | Replies : 1
Hi

i want to display an image in a table
this is my code

SqlCommand cmd1 = new SqlCommand("select * from products", conn);
conn.Open();
SqlDataReader dr = cmd1.ExecuteReader();

Response.Write("<table border= '0' >");
Response.Write("<thead>");
Response.Write("<tr ><th>Productid</th><th width='60px'>Name</th><th>Image</th><th>price</th></tr>");
Response.Write("</thead>");
Response.Write("<tbody>");
while (dr.Read())
{
Response.Write("<tr><td>" + dr["productid"].ToString() + "</td> ");
Response.Write("<td>" + dr["name"].ToString() + "</td> ");
Response.Write("<td> <asp:ImageButton ID='ImageButton1' runat='server' ImageUrl='<%# Eval('PictureURL','ProductImages\\{0}') %>' </td>");
Response.Write("<td>" + dr["price"].ToString() + "</td> ");


}
conn.Close();
Response.Write("</tbody>");
Response.Write("</table>");

but image is not showing
rest is showing correctly

Regards

K L BAIJU




Responses

Posted by: Jpchoudhari on: 6/23/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

you can not create a asp.net control object as what you have created.

you either can do as :

Take a literal control as a place holder, where you want your table to appear.

System.Text.StringBuilder strTable = new System.Text.StringBuilder();
strTable.Append("<table border='1'>");
strTable.Append("<tr>");
strTable.Append("<th>Products</th>");
strTable.Append("<th>Image</th>");
strTable.Append("</tr>");
strTable.Append("<tr>");
strTable.Append("<td>");
strTable.Append(dr["name"].ToString());
strTable.Append("</td>");
strTable.Append("<td>");
strTable.Append("</td>");
strTable.Append("<img src='" + your image path + "' alt='" + alt text + "' />");
strTable.Append("</tr>");
strTable.Append("</table>");
litTable.Text = strTable.ToString();


Thanks and Regards,
Jaydeep Choudhari


Kind Regards,
Jay

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response