If I have a Label (lblAmount) in my GridView's TemplateField, one of the simplest way to access it and modify its format is shown below:
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label myLabel = (Label)e.Row.FindControl("lblAmount");
string newLabelFormat = myLabel.Text;
const string fmt1 = "#,##0.00;(#,##0.00)";
double newAmountFormat = Double.Parse(newLabelFormat);
string myAmountFormat= newAmountFormat .ToString(fmt1);
newLabelFormat = myAmountFormat;
myLabel.Text = newLabelFormat;
}
No comments:
Post a Comment