ok so im having trouble working out the best solution to this. i have a database with two tables as follows
Untitled96

I want to load a single date based on the ID but then load each content that has that dateIDFK - this is fine in sql however im trying to load the results into a listview control.

<asp:ListView ID="LVContentHome" runat="server" OnPagePropertiesChanging="listItems_PagePropertiesChanging" EnableModelValidation="false">
                <LayoutTemplate>                
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server" />            
                </LayoutTemplate>      
       <ItemTemplate>
                    <div class="ContentDate">
                      <a><%# Eval("date", "{0:dd MMMM yyyy }")%></a> //loads date    
                      <hr class="hrDate"/>
                    </div>                   

             <div class="EntryText"> 
                <p style="margin-top:5px;"><a><%#Eval("content")%></a></p>  //loads content
             </div>                      
         </div>    
    </asp:ListView>

the problem is that the listview is expecting a date for each content that is loaded, however i only want to load the date once then load all the content under that single date, so its all grouped. for example:

RAW DATA
content1 = abc Date = 12.02.2012,
content2 = def Date = 19.09.2012,
content3 = hij Date = 12.02.2012

i want the listview to load as follows:

12.02.2012
abc
hij

19.09.2012
def

Any ideas or a better way to do this? any help will be great. thanks.

Where is your SQL statement?

Well im using LINQ to SQL, so i select the content based on the dates, i get all the dates first

ALTER PROCEDURE dbo.getAllDates

AS
    select * from tbl_Dates

    RETURN

the next sql statement will get all the content based on the date ID

ALTER PROCEDURE dbo.getEntryByDate

@dateID int /*This is the ID of the date*/

AS
    select * from tbl_Content
    where Date_id = @dateID

RETURN

i then do the following to get the data:

 using (apiContentDataContext api_Getdates = new apiContentDataContext())
            {

                var result2 = from a in api_Getdates.getALLDates() //get all dates
                              select a;

                foreach (var item in result2) // for each date, get the content entries
                {
                    var date = (Convert.ToInt32(item.Date_id));
                    var result3 = from b in api_Getdates.getEntryByDate(date)
                                  select b;
                }
             }

im not too sure how to the bind it so i get the desired effect:

DATE
CONTENT
CONTENT

DATE
CONTENT

im thinking i might have to use an array? any ideas?

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.