Click here to Skip to main content
12,634,651 members (23,973 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
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 9-Dec-12 7:06am
Comments
choudhary.sumit 9-Dec-12 23:08pm
   
why don't you use DataList control?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

<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>

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();
    }
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100