0

我的页面上有 jquery 选项卡。我想从后面的代码动态地在每个选项卡中添加选项卡和网格视图。我该如何添加。我很困惑在占位符中为 jquery 选项卡添加标记,如下所示。

<div id="ui-tabs">
<ul>
 <li><a href="#tabs-1">title1</a></li>
<li><a href="#tabs-2">title2</a></li>
<li><a href="#tabs-3">title3</a></li>
</ul>
 <div id="tabs-1">
 Content with gridview1
 </div>
 <div id="tabs-2">Content with gridview2</div>
<div id="tabs-3">Content with gridview3</div>
 </div>

我想动态添加这些网格视图,因为选项卡的数量可能会有所不同。请帮忙

4

1 回答 1

0

在热身谷歌并实施这个想法之后,我得到了这个想法。只需在后面的代码中添加 html 控件并将它们放在占位符中即可解决我的问题。请参阅 Page_Load 方法中的代码

.ASPX

<div>
        <asp:placeholder runat="server" id="placeholderDynamic">

        </asp:placeholder>
</div>

.ASPX.CS

      if (!IsPostBack)
        {              
           // Get the list from database
            List<CategoryQuesAns> quesAns = GetQuestions();

           //For Jquery tabs we require <li> in  <ul> and <div> within one outer <div>

            //Create outer div
            HtmlGenericControl divCotnainer = new HtmlGenericControl("div");
            divCotnainer.ID = "ui-tabs";
            divCotnainer.ClientIDMode = ClientIDMode.Static;

            //Create ul
            HtmlGenericControl unorderdList = new HtmlGenericControl("ul");


            //Create li's as per the number of questions
            int i = 1;
            foreach (CategoryQuesAns ques in quesAns)
            {
                HtmlGenericControl listcontrol = new HtmlGenericControl("li");
                HtmlAnchor anchor = new HtmlAnchor();
                anchor.HRef = "#tabs-"+i.ToString();
                anchor.InnerText = "Q-" + i.ToString();
                listcontrol.Controls.Add(anchor);
                //adding li in ul
                unorderdList.Controls.Add(listcontrol);
                i++;
            }

            //adding ul in the outer div
            divCotnainer.Controls.Add(unorderdList);

            //adding div in the outer div
            int j = 1;
            foreach (CategoryQuesAns ques in quesAns)
            {
                //create inner div as per the number of questions
                HtmlGenericControl divtabs = new HtmlGenericControl("div");
                divtabs.ID = "tabs-" + j.ToString();
                divtabs.ClientIDMode = ClientIDMode.Static;

                //create gridview table for each tab(li)
                Label lblQuestionText = new Label();
                lblQuestionText.Text = ques.QuestonName;

                GridView dyamicGrid=new GridView();
                dyamicGrid.ID = "Gridview-" + j.ToString();
                dyamicGrid.ClientIDMode = ClientIDMode.Static;
                dyamicGrid.CssClass = "mGrid";

                dyamicGrid.DataSource = quesAns;
                dyamicGrid.DataBind();

                divtabs.Controls.Add(lblQuestionText);
                divtabs.Controls.Add(dyamicGrid);
                divCotnainer.Controls.Add(divtabs);
                placeholderDynamic.Controls.Add(divCotnainer);
                j++;
            }         

        }
于 2013-03-26T11:52:10.283 回答