在热身谷歌并实施这个想法之后,我得到了这个想法。只需在后面的代码中添加 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++;
}
}