I am newbie in ASP.NET and C#. I want to add background color to all cell values of gridview which starts with upper letter. Here is my source code:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cell = e.Row.Cells[2];
string entity = cell.Text.ToString();
if (entity[0] >= 'A' && entity[0] <= 'Z')
{
cell.BackColor = Color.Yellow;
}
}
}
But I got this error:
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
Line 85: TableCell cell = e.Row.Cells[1];
Line 86: string entity = cell.Text.ToString();
Line 87: if (entity[0] >= 'A' && entity[0] <= 'Z')
Line 88: {
Line 89: cell.BackColor = Color.Yellow;
Source File: c:UsersEricDefault.aspx.cs Line: 87
Please help me to solve this error
Thank you to all
