Click here to Skip to main content
16,004,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have many image controls on my asp.net web page and I have stored image urls in my database , so I have created string array and retrived image urls in it So, i want to insert the url in the image control using image.imageurl.

How to do it using loop ??
As I have many image controls to use many lines of code.?
Posted

<td id="data"  runat="server"">

string html="";
foreach(DataRow row in dt.Rows)
{
html+="<tr>";
html+="<td><img src="+row[0].ToString()+"></td>";
html+="</tr>";
}
data.innerHtml=html;
</td>
 
Share this answer
 
v2
Comments
Member 11343372 30-Dec-14 8:59am    
I didn't get this this is too high then my knowledge please explain
thanks
Sid_Joshi 31-Dec-14 0:56am    
create table in string html variable in html format and write this html text on web page it will looks like a web page
Design view
<asp:repeater id="image" runat="server" xmlns:asp="#unknown">
<itemtemplate>
<asp:image id="Image1" runat="server" imageurl="<%#Eval(" img_url","~image="" {0}="" 0.jpg")="" %&gt;"="">





CS coding
namespace
C#
using System.Web.Configuration;
using System.Data;


C#
protected void bind_links()
    {
        string query = "select * from img_url ";
        string constring=WebConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (SqlConnection conn=new SqlConnection(constring))
        {
            using (SqlCommand comm=new SqlCommand(query))
            {
                using (SqlDataAdapter da=new SqlDataAdapter())
                {
                    comm.Connection = conn;
                    da.SelectCommand = comm;
                    using (DataTable dt=new DataTable())
                    {
                        da.Fill(dt);
                       image.DataSource = dt;
                        image.DataBind();
                    }
                }

            }

        }
    }
 
Share this answer
 
Try This
C#
DataTable dt = new DataTable();
Image[] img = null;
foreach (DataRow row in dt.Rows)
{
    int len = 0;
    if (img.Length > 0)
        len = img.Length;
    Array.Resize(ref img, len+1);
    img[len].ImageUrl = row["imageUrl"].ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900