Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to retrieve images from a database and display them in a tiled view(at least three on a row) but i don't know how to go about that could someone please shed light on this for me?
Posted
Comments
choudhary.sumit 9-Dec-12 23:08pm    
why don't you use DataList control?

1 solution

XML
<asp:DataList ID="dl" runat="server" RepeatDirection="Horizontal">
                <ItemTemplate>
                    <asp:Image ID="img" runat="server" ImageUrl='<%#"~/images/"+Eval("image") %>' Width="160px"
                                    Height="169px" />
                </ItemTemplate>
            </asp:DataList>

C#
protected void Page_Load(object sender, EventArgs e)
    {
          binddatalist();
    }

    private void binddatalist()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Demo"]);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from contact", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            dl.DataSource = dt;
            dl.DataBind();
        }
        con.Close();
    }
 
Share this answer
 
Comments
Member 9465564 10-Dec-12 7:28am    
Thank You. This will help display it horizontally but what if i have multiple rows hoe do i go about that?

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