Convert the first letter of each word to uppercase in some columns of a gridview

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow) {
  string[] TitleCaseFields = {
   "FieldName1",
   "FieldName2"
  };
  foreach (DataControlFieldCell GridDataControlFieldCell in e.Row.Cells) {
   BoundField GridBoundField = GridDataControlFieldCell.ContainingField;
   string GridDataField = GridBoundField.DataField;
   if (TitleCaseFields.Contains(GridDataField) == true) {
    GridDataControlFieldCell.Text = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Server.HtmlDecode(GridDataControlFieldCell.Text.ToLower));
   }
  }
 }
}

No comments:

Post a Comment