[英]Can you truncate results of a databound templatefield in a gridview?
I've got a field that retrieves a folder path. 我有一个检索文件夹路径的字段。 However it makes the column width too wide.
但是,这会使列宽过宽。 I was wondering if there was a way to truncate the returned value so I can show just the file name without it's path.
我想知道是否有一种方法可以截断返回的值,以便仅显示没有路径的文件名。
<asp:TemplateField ControlStyle-CssClass="columnWidth"
HeaderText="File Name " SortExpression="FileName">
<EditItemTemplate>
<asp:Label ID="Label12" runat="server"
Text='<%# Bind("FileName")%>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton runat="server" ID="download"
CausesValidation="false" OnClick="download_Click"
CommandArgument="<% %>" CommandName="Download"
Text='<%#Bind("FileName")%>'></asp:LinkButton>
</ItemTemplate>
<HeaderStyle CssClass="gridHeader columnWidth" ForeColor="#A1ADBB" />
</asp:TemplateField>
.aspx file .aspx文件
<asp:Label ID="Label12" runat="server"
Text='<%# GetFileName( Convert.ToString( Eval("FilePath") ) ) %>'
</asp:Label>
.cs file .cs文件
using System.IO;
protected string GetImagePath( string FilePath)
{
return Path.GetFileName(FilePath);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.