How to set BoundColumn DataFormatString in CodeBehind?

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?
 
G

Guest

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top