question

YanAung-4841 avatar image
0 Votes"
YanAung-4841 asked LanHuang-MSFT answered

How to create Gridview Header dynamically from database?

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 :)


dotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LanHuang-MSFT avatar image
0 Votes"
LanHuang-MSFT answered

Hi @YanAung-4841,
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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.