Hi anjali600,
Check this example. Now please take its reference and correct your code.
HTML
<asp:GridView ID="grdCalculate" runat="server" GridLines="Horizontal" OnRowDataBound="OnRowDataBound">
</asp:GridView>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
table {
border: 1px solid #ccc;
}
table th {
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td {
padding: 5px;
border-color: #ccc;
}
.symbol {
text-align: left;
float: left;
}
.number {
text-align: right;
float: right;
}
</style>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add(new System.Data.DataColumn("Title"));
dt.Columns.Add(new System.Data.DataColumn("Number"));
dt.Rows.Add("Number", 12.3);
dt.Rows.Add("Pages", 45789);
dt.Rows.Add("requirements", 23456);
dt.Rows.Add("Price", 12);
dt.Rows.Add("Property", 25);
grdCalculate.DataSource = dt;
grdCalculate.DataBind();
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblSymbol = new Label();
lblSymbol.Text = "$";
lblSymbol.CssClass = "symbol";
Label lblNumber = new Label();
lblNumber.Text = Convert.ToDecimal(e.Row.Cells[1].Text).ToString("N0");
lblNumber.CssClass = "number";
e.Row.Cells[1].Controls.Add(lblSymbol);
e.Row.Cells[1].Controls.Add(lblNumber);
e.Row.Cells[1].Width = 100;
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As Data.DataTable = New Data.DataTable()
dt.Columns.Add(New Data.DataColumn("Title"))
dt.Columns.Add(New Data.DataColumn("Number"))
dt.Rows.Add("Number", 12.3)
dt.Rows.Add("Pages", 45789)
dt.Rows.Add("requirements", 23456)
dt.Rows.Add("Price", 12)
dt.Rows.Add("Property", 25)
grdCalculate.DataSource = dt
grdCalculate.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblSymbol As Label = New Label()
lblSymbol.Text = "$"
lblSymbol.CssClass = "symbol"
Dim lblNumber As Label = New Label()
lblNumber.Text = Convert.ToDecimal(e.Row.Cells(1).Text).ToString("N0")
lblNumber.CssClass = "number"
e.Row.Cells(1).Controls.Add(lblSymbol)
e.Row.Cells(1).Controls.Add(lblNumber)
e.Row.Cells(1).Width = 100
End If
End Sub
Screenshot