954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Modify data from before binding to gridview

Im creating a project where the a blog can be submitted, the date is stored in the database as dd/mm/yy, however im using LINQ to SQL to get the date as well as other information, the problem comes when i want to display the date in a particular layout (similar to this website: http://highrockmedia.com/tags/css ).

below is the code im using to get the data but i want to split the date up into different labels so i can position them where i want. Is this the best option?

using (apiContentDataContext api_GetContent = new apiContentDataContext())
            {

                var result = from c in api_GetContent.getAllContent()                   

                             select new
                             {
                                 c.content_Date,
                                 c.content_Intro,                                
                                 c.content_Main,
                                 c.content_Title                   

                             };              
                
               
                LVContentHome.DataSource = result;
                LVContentHome.DataBind();


but now the date has been retrieved from the database i cannot do anything with it, if i try it result in an error.


The alternative way was to do the following:

<a><%# Eval("content_Date", "{0:dd}")%></a>
<a><%# Eval("content_Date", "{0:MM}")%></a>
<a><%# Eval("content_Date", "{0:yyyy}")%></a>


I don't know if there's a better way to do this? Any help/suggestions would be very helpful.

Regards
BarrieGrant1

barriegrant1
Light Poster
29 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

split the parts in your Linq statement instead of accepting the date as a whole value:

select new {
    c.content_Date.Day,
    c.content_Date.Month,
    c.content_Date.Year,
    c.content_Intro,                                
    c.content_Main,
    c.content_Title                   
};
Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

Thanks for your help, I have tried a number of ways to split the date as you suggested. Is it best to do this as an array or is there a split method that i can do within the stored procedure.

Regards
BarrieGrant1

barriegrant1
Light Poster
29 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: