DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

Using string.Format with Eval in GridView.TemplateField.ItemTemplate

By Ashok Nalam on 14 Dec 2013 | Category: C# | Tagged: string .NET gridview 
  Discuss Add Comment   |  
Add rating Rate this resource   
When we are binding data to GridView we might need to format the data. Below code shows how can we use string.Format with Eval.

string.Format with Eval:

<asp:TemplateField HeaderText="Full Name">
    <ItemTemplate>
<%# string.Format("{0} {1}", Eval("FirstName"),Eval("LastName")) %>
</ItemTemplate>
</asp:TemplateField>

Direct format for Control:

<asp:TemplateField HeaderText="Full Name">
    <ItemTemplate>
<asp:Label ID="lblFullName" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

DataBinder.Eval with Format:

DataBinder.Eval method itself has string format as parameter. Using this we can format with single value Eval.
'<%# DataBinder.Eval(Container.DataItem, "createdatetime", "{0:MM/dd/yyyy}") %>'
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys