selva kumar

selva kumar

  • NA
  • 557
  • 189.9k

How to display image name without extension using data list?

Dec 4 2013 3:14 AM
Hi friends here i m using datalist control to display images from folder with name.its working fine but the images name displayed with extension( like .jpg,.png).I want to display only image name without their extension can any one help me out...
here is my code.....

<asp:DataList ID="DataList1" runat="server"  RepeatColumns="5" CellPadding="5">
                                            <ItemTemplate>
                                            <asp:Image ID="lblimg" runat="server" Height="180px" Width="130px" ImageUrl='<%# Bind("Name","~/Books/{0}") %>' /><br />
                                            <asp:label ID="lbltitle" runat="server" Visible="true" Text='<%# Bind("Name") %>'>
                                            </asp:label>
                                            </ItemTemplate>
                                            <ItemStyle BorderColor="#660000" BorderWidth="1px" HorizontalAlign="Center"
                                            VerticalAlign="Bottom" />
                                        </asp:DataList></td>

C#:

DirectoryInfo dir = new DirectoryInfo(MapPath("Movies"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        DataList2.DataSource = listItems;
        DataList2.DataBind();

Answers (3)