locked
Dynamically bind data from a foreach loop in ASP.NET Site.Master RRS feed

  • Question

  • User-2137363181 posted

    I have an ASP.NET C# web form project.
    I need to know the possibility of updating the Horizontal Menu with data from the database via a foreach loop in the Site.Master.Designer.cs page.

    The menu is like,
        Parent1
           Child 1
           Child 2
        Parent 2
           Child 1
           Child 2
           Child 3
           Child 4
    and all the Parent and Child items are binded according to the user permissions of the logging user.
    That menu item list is the data that I'm going to take from the foreach loop.


    The below images show an example of a menu what I'm trying to develop.
    sample menu image 1
    sample menu image 2

    Thanks in advance

    Monday, October 19, 2020 7:15 AM

All replies

  • User-1330468790 posted

    Hi ptnawoda,

     

    ptnawoda

    I need to know the possibility of updating the Horizontal Menu with data from the database via a foreach loop in the Site.Master.Designer.cs page.

    It is possible to bind the menu or tree view control with recursively data binding. You have to bear in mind that those controls are derived from HierarchicalDataBoundControl and the data source controls should be derived from HierarchicalDataSourceControl.

     

    More over, you should not use the designer.cs but directly use the code behind .aspx.cs of the site.Master to bind the data (You might need to bind data inside if(!IsPostBack) block). 

      

    ptnawoda

    The below images show an example of a menu what I'm trying to develop.

    Sorry that I am not able to see the images. You could upload the images on some image host and post the url of the images in text editor.

     

    Best regards,

    Sean

    Monday, October 19, 2020 11:06 AM
  • User409696431 posted

    You have to get a link sharable with everyone for us to see files on your google drive.

    Example from my google drive: Bears at my bird feeders https://drive.google.com/file/d/1Sg6ukCCbuNzvpqIDj_SF9I25Txw9O6pq/view?usp=sharing

    Mind you, the image of your menu isn't related to your question, which has been answered. Its up to you to do the coding.  If you have a specific problem when you are doing that, come back with your code and ask a question.

    Monday, October 19, 2020 3:33 PM
  • User-2137363181 posted

    Thank you very much for your kind response

    Wednesday, October 21, 2020 7:04 AM
  • User-2137363181 posted

    Thank you very much for your kind response

    You have to get a link sharable with everyone for us to see files on your google drive.

    Example from my google drive: Bears at my bird feeders https://drive.google.com/file/d/1Sg6ukCCbuNzvpqIDj_SF9I25Txw9O6pq/view?usp=sharing

    Mind you, the image of your menu isn't related to your question, which has been answered. Its up to you to do the coding.  If you have a specific problem when you are doing that, come back with your code and ask a question.

    Wednesday, October 21, 2020 7:07 AM
  • User-1330468790 posted

    Hi ptnawoda,

     

    Does above answers help?

    If you still have any problem, feel free to let us know.

     

    Best regards,

    Sean

    Thursday, October 22, 2020 7:27 AM