How to create Gridview Header dynamically from database?

Yan Aung 1 Reputation point
2021-10-06T08:22:55.377+00:00

Hello everyone!
Now I m facing problem with gridview header problem.
In my project I have 2 tables from database.
Table One
ItemName | ItemID
Apple | 1
Mango | 2
Pineapple | 3
- |-
- |-
- |-
- |-
- |-

  • List item | 100
    =================
    Table Two
    PeopleID | FruitID
    1| 10
    1|11
    1|33
    1|45
    2|1
    2|2
    2|4
    etc...

1) I want gridview header columns dynamically base on Second table.
When I select PeopleID No -1 , Gridview appears like-

ID|10|11|33|45|

When I select PeopleID No 2 , Gridview appears like-

ID|1|2|4|

Please help me to finish my project.
Thanks :)

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,288 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 25,876 Reputation points Microsoft Vendor
    2021-10-07T10:03:58.57+00:00

    Hi @Yan Aung ,
    First, join two tables with sql statement
    Second, bind the header data in the rowdatabound event
    Third, in this event, according to the selected value, sql query table
    The result of the query is stored in the datatable
    Return datatable to grid view header
    Best regards,
    Lan Huang

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

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments