Creating dynamic boxes (divs) with different title

2019-08-02 09:32发布

Wish you all are doing fine at the start of a new year

I am a beginner developer. I am developing a website. I have few divs which made up dragable boxes enhanced by jquery portlets. Please see the codes below.(html).

    <div class="portlet">
    <div class="portlet-header"> Category A </div>
    <div class="portlet-content">   
    </div>
    </div>

    <div class="portlet">
    <div class="portlet-header"> Category B </div>
    <div class="portlet-content">   
    </div>
    </div>

I also have a stored procedure from the database developer that return the list of categories. Depending on the user selection, the list of categories can vary. So i have to dynamically create those Boxes. Each categories returned by the SP should replace Category A, Category B, and so on. As i can't know the number of categories returned by the SP i just hard coded those divs. My question is simply how ? How can i achieve this?

I have to be using VB.net in VS 2010. The database is in SQL server 2008. THanks so muchhhhhh and pls have as much detail as you can in your reply as i am a beginner. Thankssssssssssss.

1条回答
▲ chillily
2楼-- · 2019-08-02 10:27

OK, so the way I do this is, you setup a generic handler on your web site to query the database for your categories. You will need to print this data on the page as JSON so jquery can easily understand it, then on your web page that you want to display the info, use jquery's getAjax function to call your generic handler, and then loop through the categories your handler returns creating a div for each.

You can also do this with ajax and a repeater on asp.net, simply add a repeater to the page, setup the ItemTemplate with your div design, and hook the repeater to your SP in the code behind.

If you have questions about parts of this, just comment and I will try to help.

查看更多
登录 后发表回答