How to append text to a Eval databound field in gridview in asp.net?


We will use Databinders to bind data to controls.

Sometimes we need to append some text before data or after data… ex: we can append Download text before to DocumentName

we can do this as follows

Append Text before Eval Data

  1. <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#"Download" +" "+ Eval("DocumentName").ToString() %>'/>

Append Text before and after Eval Data

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#"Download" +" "+ Eval("DocumentName").ToString()+" "+ "TextFile"%>'/>

Concatenating Two Eval binders

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#"Download" +" "+ Eval("DocumentName").ToString()+" as "+ Eval("Format").ToString()%>'/>

By using string.Format() Method in Eval

Append Text before Eval Data

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#string.Format("Download {0}",Eval("DocumentName")) %>'/>

Append Text before and after Eval Data

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#string.Format("Download {0} as TextFile",Eval("DocumentName")) %>'/>

Concatenating Two Eval binders

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/DwonloadFile.png" ToolTip='<%#string.Format("Download {0} as {1}",Eval("DocumentName"),Eval("Format")) %>'/>

Thanks…

Venki

Hi if this is not solving ur problem please leave ur requirement as a comment below this post…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s