如何在ASP.NET中将特定文本添加到gridview单元格值

时间:2014-02-10 10:55:37

标签: asp.net gridview

在我的gridview中,有一个以'Price'为标题的列作为标题文本。我需要添加'Rs'。在该列中所有单元格值的开头。

这是我的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>

请帮助。提前致谢

1 个答案:

答案 0 :(得分:2)

使用代码隐藏,RowDataBound是正确的事件:

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;
    }
}