24 February 2015

Accessing The Label Inside The DetailsView DataBound

 If I have a Label (lblAmount) in my DetailsView's TemplateField, one of the simplest way to access it and modify its format is shown below:

       Label myLabel = dvIncomeSummary.FindControl("lblAmount") as Label;
       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