Here is a sample implementation for a RowDataBound method for the GridView, which looks for cells having only numbers, comma (,) and a period(.) in the contents and if it finds a match, it aligns it to the right:
// C#>
protected void gridViewt_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Right align the column if its a numerical value
for (int i = 0; i < e.Row.Cells.Count; i++)
{
if(Regex.IsMatch(e.Row.Cells[i].Text.Trim(), @"^[0-9,.]*$"))
{
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
}
}
}
}
' VB.Net
Protected Sub gridViewt_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
' Right align the column if its a numerical value
For i As Integer = 0 To e.Row.Cells.Count - 1
If Regex.IsMatch(e.Row.Cells(i).Text.Trim(), "^[0-9,.]*$") Then
e.Row.Cells(i).HorizontalAlign = HorizontalAlign.Right
End If
Next
End If
End Sub
You can change the regular expression depending on what all do you you want to match to align the data to the right.