Tuesday, 16 December 2014

How to split the data in ItemTemplate Eval in gridview in asp.net

Basically i have an entity that gets bind to my Gridview and has string value like this

"Testing Apps.pdf" 

But i want to show the only Name of the file, the better way to handle instead of ServerSide we can achieve this in Eval fields in GridView ItemTemplate only by Using Split function.
 



<asp:GridView ID="GridView1" BorderWidth="0px" runat="server" ShowHeader="false" ShowFooter="false" AutoGenerateColumns="False" Width="320px">
    <Columns>
          <asp:TemplateField>
                <ItemTemplate>
<asp:LinkButton runat="server" OnClick="lnkView_Click" ID="lnkView"   Text='<%# Eval("FileName").ToString().Split(Convert.ToChar("."))[0] %>' ></asp:LinkButton>
               </ItemTemplate>
         </asp:TemplateField>
      </Columns>
</asp:GridView>


Here i Specify data in Grid Splitted by "."

No comments:

Post a Comment