1

嗨,我是 J Query 的新手,在我的项目中,我想从 C# 代码后面实现 J Query Accordion,但我不知道如何使用以下代码向 jquery Accordion 添加控件,但这会将控件添加到 Accordion 选项卡而不是内容

下面是aspx的代码

<script type="text/javascript">
    $(function () {
        $("#accordion").accordion({
            heightStyle: "content"
        });
    });
</script>



 <div id="accordion" runat="server">
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <h3>
                <%# DataBinder.Eval(Container.DataItem, "Mobile_Name")%>
            </h3>
            <div>
                <p>
                    <%# DataBinder.Eval(Container.DataItem, "Description")%>
                </p>
            </div>
        </ItemTemplate>
    </asp:Repeater>
</div>

以下 .cs 代码

TextBox txtEmail = new TextBox();
     txtEmail.ID = "txtEmail";



    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
    SqlDataAdapter da = new SqlDataAdapter("select * from Mobile", con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    Repeater1.DataSource = ds;
    Repeater1.DataBind();
    accordion.Controls.Add(txtEmail);

请告诉我解决方案谢谢

4

1 回答 1

3

如果您希望您的 txtEmail 成为手风琴的一部分,您必须使用与手风琴兼容的标记。而不是只添加文本框添加以下内容:

// First add the header component
accordion.Controls.Add(new HtmlGenericControl("h3") { InnerText = "Email" });
// Then create the div for the accordion content
HtmlGenericControl div = new HtmlGenericControl("div");
// Add your textbox to the content div for the accordion
div.Controls.Add(txtEmail);
// Finally add the div to the accordion completing the accordion tab set
accordion.Controls.Add(div);

注意:代码是手写的,没有编译验证。如果它不编译让我知道:)

于 2012-10-23T11:44:26.937 回答