I have a gridview databound the following way in the code behind:
Dim dirInfo As New DirectoryInfo(Server.MapPath("~/RawDataFiles"))
gvFiles.DataSource = dirInfo.GetFiles("*.*").OrderByDescending(Function(f) Right(f.Name, 8)) 'Files are sorted by Last 8 characters
gvFiles.DataBind()
infodemers
Member
86 Points
91 Posts
Bind boundfield with last 8 characters only of binded values
Nov 16, 2012 07:11 PM|LINK
I have a gridview databound the following way in the code behind:
Dim dirInfo As New DirectoryInfo(Server.MapPath("~/RawDataFiles")) gvFiles.DataSource = dirInfo.GetFiles("*.*").OrderByDescending(Function(f) Right(f.Name, 8)) 'Files are sorted by Last 8 characters gvFiles.DataBind()In the ASPX page:
<asp:GridView runat="server" ID="gvFiles" Font-Name="Verdana" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee" HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True" CellPadding="4" Font-Names="Verdana" ForeColor="#333333" GridLines="None" AllowSorting="true"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns> <asp:TemplateField HeaderText="File Name" ItemStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:HyperLink ID="HL1" runat="server" NavigateUrl="" Text='<%# Eval("Name") %>' Target="_blank" /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField='right(Name,8)' HeaderText="Time" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:yyyy-MM-dd}"> <ItemStyle HorizontalAlign="Center"></ItemStyle> </asp:BoundField> </Columns> <EditRowStyle BackColor="#999999" /> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" Font-Size="15pt" ForeColor="White"> </HeaderStyle> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#E9E7E2" /> <SortedAscendingHeaderStyle BackColor="#506C8C" /> <SortedDescendingCellStyle BackColor="#FFFDF8" /> <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> </asp:GridView>I am trying to bind the boundfield with the last 8 characters from the FileInfo Name in the datasource.
Any idea how to have this done?
me_ritz
Star
9337 Points
1447 Posts
Re: Bind boundfield with last 8 characters only of binded values
Nov 16, 2012 07:21 PM|LINK
You can get this like -
<asp:TemplateField HeaderText="File Name" ItemStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:HyperLink ID="HL1" runat="server" NavigateUrl="" Text='<%# Right(Eval("Name"), 8)%>' Target="_blank" /> </ItemTemplate> </asp:TemplateField>infodemers
Member
86 Points
91 Posts
Re: Bind boundfield with last 8 characters only of binded values
Nov 16, 2012 07:30 PM|LINK
Yes, that is the way to do it.
It was for the Boundfield, so I converted the Boundfield to a TemplateField as follow and it works!
<asp:TemplateField HeaderText="Date Obtained" ItemStyle-HorizontalAlign="Left"> <ItemTemplate> <asp:Label ID="Lb1" runat="server" Text='<%# Right(Eval("Name").ToString(),8) %>'></asp:Label> </ItemTemplate> </asp:TemplateField>Thanks me_ritz!