locked
How to show specific data into gridview where header text will be a single column from database? RRS feed

  • Question

  • User-1653337575 posted

    Hello everybody! I am an asp.net junior and i am trying to build a simple livescore website. I have my database containing time, homeTeam, awayTeam, result, competition where this match is being played ect. I have to show the competition as a header text and the belonging matches under it. As you know, there are different competitions within a day and every competition should have it's matches under it. What would be the best solution to this?

    Thanks in advance!

    Tuesday, December 22, 2015 10:54 PM

Answers

  • User614698185 posted

    Hi nardiM,

    I think you could use DataList and have Gridview inside, please refer to this tutorial:

    http://www.c-sharpcorner.com/blogs/datalist-have-gridview-inside1

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 5:37 AM
  • User-1716253493 posted

    I agree with Candice Zhou solution, you can use nested gridview or other data control like listview, datalist etc

    First populate parent control with competition

    SELECT DISTINCT COMPETITION FROM YOURTABLENAME

    then populate child grid by this query.

    SELECT * FROM YOURTABLENAME WHERE COMPETITION = @COMPETiTION

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 5:53 AM

All replies

  • User614698185 posted

    Hi nardiM,

    Welcome to ASP.NET Forums!

    You could use Eval in the HeaderTemplate, like below:

    <HeaderTemplate >
        <asp:Label ID="lblHeader" runat="server" Text='<%# Eval("competition") %>'></asp:Label>     
    </HeaderTemplate>
    

    Best Regards,

    Candice Zhou

    Wednesday, December 23, 2015 1:59 AM
  • User-1653337575 posted

    Hello Candice,

    Thank you for your quick response but i still find it difficult. I should display multiple match details under the header text of competition. It will be something like this:

               Competition 1

    ----------------------------------------------------

    Match 1: Time   |   Team x   |   result   |   Team y

    Match 1: Time   |   Team x   |   result   |   Team y

    ...

    ----------------------------------------------------

               Competition 2

    ----------------------------------------------------

    Match 1: Time   |   Team x   |   result   |   Team y

    Match 1: Time   |   Team x   |   result   |   Team y

    ...

    I have these columns in my database: Id, date&time, competition, homeTeam, awayTeam, HT result, FT result.

    Grand regards!

    Saturday, December 26, 2015 7:52 PM
  • User614698185 posted

    Hi nardiM,

    I think you could use DataList and have Gridview inside, please refer to this tutorial:

    http://www.c-sharpcorner.com/blogs/datalist-have-gridview-inside1

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 5:37 AM
  • User-1716253493 posted

    I agree with Candice Zhou solution, you can use nested gridview or other data control like listview, datalist etc

    First populate parent control with competition

    SELECT DISTINCT COMPETITION FROM YOURTABLENAME

    then populate child grid by this query.

    SELECT * FROM YOURTABLENAME WHERE COMPETITION = @COMPETiTION

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 29, 2015 5:53 AM