ASP.NET: DataGrid Date Formatting

liunx

Guest
Hey guys, i'm using ASP.NET to get Excel data using a datagrid. I've got a column that's a Date formatted column, and even though the excel format is just mm/dd/yyyy when i view the ASP page it shows up as mm/dd/yyyy 12:00 AM.

Now i've seen another solution to just specify the property of the actual Date column with the string i want... but remember these are all auto-generated. I need to find a way to tell it to handle the date a certain way IF it shows up (this is a select-based data, so date isn't always present).

I'm brand new to ASP.NET and this is my first project working with it - and by what i've read so far .NET seems to be an absolutely fantastic improvement. The most impressive feature i've seen so far are the controls, along with the error reporting. My god, compared to the tedius way errors had to be hunted in the old ASP... the new error page generated is just fabulous.

What do you guys think of .NET?if your using bound columns then you can specify the format of the output string

{0:X} where X is the string format for the datetime structure item. Just as money values you can use
{0:C} where it returns the value based on the current executing threads locale settings, for each culture.

look up DateTime.ToString for the formats allowed.
by the way the "0" value is the index of the passed in variable parameters.I can't seem to get it to work.

No matter what string i specify for the DataFormatString property of BoundColumn... it's still the same =/


<asp:datagrid width ='93%' HorizontalAlign="Center" id="data" runat="server" >
<HeaderStyle Font-Bold="True" ></HeaderStyle>
<FooterStyle></FooterStyle>
<Columns>
<asp:TemplateColumn>
<itemtemplate>
<asp:CheckBox id="chkSelect" runat="server" ></asp:CheckBox>
</itemtemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

i just kinda added the BoundColumn control randomly... not quite sure how those really work lol.

<-- .NET newbie >_<

EDIT: Yeah adding the random BoundColumn screwed up the autogen. Can you just tell me what to modify on my code so it handles a Date column properly? =D<Columns>
<asp:TemplateColumn>
<itemtemplate>
<asp:CheckBox id="chkSelect" runat="server" ></asp:CheckBox>
</itemtemplate>
</asp:TemplateColumn>
</Columns>



thats not a bound column its a templated column.

You can not auto generate and create your own columns.


<asp:BoundColumn DataField="DateField" HeaderText="DateCreated" DataFormatString="mm-dd-yyyy"/>




thats a bound column and look at the datetime.toString structure it will show you samples of code that you can use to format the output.What do you guys think of .NET?

I have worked with it too, and i think very great of it.well i just meant is there a way to specify formatting for columns that are auto-generated... but i guess not
 
Back
Top