Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to bind datalist in asp.net c# to show image gallery.i want to show images in datalist at dynamically without help of database.can anybody help me please
Posted
Comments
Vani Kulkarni 12-Jul-12 2:05am    
What do you mean "without database"?
[no name] 12-Jul-12 2:06am    
means there is no linking with database only bind images on front end

XML
<asp:DataList ID="dtlist" runat="server" ForeColor="#333333" RepeatColumns="5">
<%-- <AlternatingItemStyle BackColor="White" ForeColor="#284775" />
          <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
          <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />--%>
          <ItemStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left"/>
             <ItemTemplate>
             <ul class="thumbs noscript">

                 <li>
                  <a class="thumb" href='<%# Eval("Name","images/portfolio_one/{0}")%>'>
                             <img src='<%# Eval("Name","images/portfolio_one/{0}")%>' width="80" height="90" alt='<%# Eval("Name") %>'/>
                           </a>
                   </li>
             </ul>
                   </ItemTemplate>
                      
             <SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /></asp:DataList>




C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataList();
        }
    }
    protected void BindDataList()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("images/portfolio_one/"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        dtlist.DataSource = listItems;
        dtlist.DataBind();

    
    }
 
Share this answer
 
Comments
rinkal bagathriya 17-Apr-13 1:30am    
how to bind data from database in datalist
shimith 17-Jan-14 1:25am    
how to add paging in this datalist..?
shambhoo745 26-Dec-14 6:05am    
very nice
 
Share this answer
 
Comments
[no name] 12-Jul-12 8:07am    
thnx alot 1st link is helpfull to me
Raje_ 28-Aug-12 6:52am    
then why didn't you accept his answer?
Raje_ 28-Aug-12 6:51am    
BTW who has downvoted you?
nice links, +5

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