日期:2014-05-17  浏览次数:20569 次

ASP.NET中DataList的问题~!
我弄了一个相册浏览的网页 想问下在DataList里面怎么才能去掉图片的扩展名只显示文件名啊?

C# code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUpload.aspx.cs" Inherits="FileUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function show() {
            alert("图片格式错误~!");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="lblImageFile" Text="Image File:" AssociatedControlID="upImage" runat="server" />
    <asp:FileUpload ID="upImage" runat="server" />
    <asp:Button ID="btnAdd" runat="server" Text="Add Image"  OnClick="btnAdd_Click"/>
    <div>
    
    </div>
    <div style=" text-align:center;">
        <asp:DataList ID="dlstImages" runat="server" RepeatColumns="4" 
            HorizontalAlign="Center">
         <ItemTemplate>
           <asp:Image ID="Image1"
                ImageUrl='<%# Eval("Name","~/UserImage1/{0}") %>'
                style="width:200px"
                Runat="server" />
                <hr />
                <%# Eval("Name") %>
                <hr />
         </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>





------解决方案--------------------
Path.GetFileNameWithoutExtension(Eval("Name").ToString())
------解决方案--------------------
<asp:Image ID="Image1"
ImageUrl='<%# "~/UserImage1/"+System.IO.Path.GetFileNameWithoutExtension(Eval("Name").ToString()) %>'
style="width:200px"
Runat="server" />