How to set BoundColumn DataFormatString in CodeBehind?

  • Thread starter Thread starter Randall Parker
  • Start date Start date
R

Randall Parker

In ASP.Net v1.1 and C# suppose one has:
protected System.Web.UI.WebControls.DataGrid MyGrid;

In Page_Load I want to do the equivalent of:

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:d}";

or

MyGrid.Columns[MyDateColumnIndex].DataFormatString="{0:g}";

depending on some user style flag that determines how much date/time details the user
wants to see.


But DataFormatString is not a field for the Columns[] array.

Is there a way to do this?
 
Hi Randall,

You needed to cast the column to its type, e.g.

((BoundColumn)MyGrid.Columns[MyDateColumnIndex]).DataFormatString = "{0:d}";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top