我的页面上有jquery标签。我想在代码后面动态地在每个标签中添加标签和gridview。我该如何添加呢。我很困惑为占位符中的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>
我想动态添加这些gridview,因为标签数量可能会有所不同。请帮忙
答案 0 :(得分: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++;
}
}