Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with displaying database date in a specific format

Status
Not open for further replies.

JeroenDortmans

Technical User
Aug 7, 2001
56
NL
I have created an ASP.net webpage where people of my soccer club can add information of the matches to play.
The information is stored in an Access database, I use VS 2005 as design tool and have a server with ASP.NET 2.0.
I have defined a format of how to display this information on the website so that everybody can see the schedule of the matches.

Here an overview of the data as it is stored in the Access database.

------------------------------------------------------------
| date | time | home team | visiting team | remarks |
------------------------------------------------------------

Here an overview how I want to display the information.

-----------------------------------------------------
| date A
-----------------------------------------------------
| home team | visiting team | time | remarks
-----------------------------------------------------

-----------------------------------------------------
| date B
-----------------------------------------------------
| home team | visiting team | time | remarks
-----------------------------------------------------

When there are multiple matches to be played on one date these matches must all be listed “under” one date.
Here is an example on the website, this is hand coded.
The question I have is, how can I accomplish displaying the information of the matches in the format I have defined?
 
You can use nested Repeaters or nested GridViews depending on the amount of flexibility you need when formatting the results.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Although the 4guys article is good, it can get confusing, imo

heres a quick and dirty datalist that will accomplish what i gather is what you are looking for.

TODO: Apply your formatting to the MatchInfo section (css formatting or tables) for alignment: Also update your DateFormatStrings of 0:M (Month, Day) and 0:t (time) to your preferred formatting

Code:
<asp:DataList ID="dlSoccerMatches" runat="server" OnItemDataBound="soccerMatches_IDB"
    Style="font-family: Verdana; font-size: 9pt;">
    <HeaderTemplate>
        Soccer Match Listing By Date
    </HeaderTemplate>
    <ItemTemplate>
        <div id="MatchDate" runat="server" style="font-weight: bolder;">
            <%# DataBinder.Eval(Container.DataItem,"Date","{0:M}") %>
        </div>
        <div id="MatchInfo" runat="server" style="padding-left: 10px;">
            <%# DataBinder.Eval(Container.DataItem,"HomeTeam") %>
            <%# DataBinder.Eval(Container.DataItem, "VistingTeam")%>
            <%# DataBinder.Eval(Container.DataItem,"Time","{0:t}") %>
            <%# DataBinder.Eval(Container.DataItem,"Remarks") %>
        </div>
    </ItemTemplate>
</asp:DataList>

Code:
public void soccerMatches_IDB(object sender, DataListItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Header)
    {
        ViewState["soccerDateHeader"] = ""; //reset
    }
    else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        string rowDate = DataBinder.Eval(e.Item.DataItem,"Date").ToString();
        string savedDate = ViewState["soccerDateHeader"].ToString();
        if (rowDate == savedDate)
        {
            ((HtmlGenericControl)(e.Item.FindControl("MatchDate"))).Visible = false;
        }
        else
        {
            ViewState["soccerDateHeader"] = rowDate;
        }
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top