user2772568
user2772568

Reputation: 75

How to add a particular text to gridview cell value in ASP.NET

In my gridview, there is a column with 'Price' as the Header Text. I need to add 'Rs.' in the beginning of all the cell values in that column.

Here is my Gridview..

<asp:GridView ID="gridViewStock" runat="server"  AutoGenerateColumns="false">
 <Columns>
 <asp:TemplateField HeaderText="UCP" ItemStyle-Width="14%">
  <ItemTemplate>
     <asp:Label ID="lblPrice" runat="server" Text='<%# Eval("Price") %>'></asp:Label>  
  </ItemTemplate>
 </asp:TemplateField>
</cloumns>
</GridView>

Please Help. Thanks in advance

Upvotes: 1

Views: 3335

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460138

Use codebehind, RowDataBound is the correct event:

protected void gridViewStock_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Label lblPrice = (Label) e.Row.FindControl("lblPrice");
        lblPrice.Text = "Rs." + lblPrice.Text;
    }
}

Upvotes: 2

Related Questions