0

我正在使用我的数据库中的数据构建一个可编辑的表单,这需要使用 ASP.NET 控件。我在 HTML 中得到了这个工作,但是当我添加 .NET 部分时,我被卡住了。

情况如下:我在页面上显示了一个标签,其下方有一个编辑按钮。应该发生的是,一旦按下编辑按钮,标签就会变成一个 .NET 下拉列表,其中包含来自数据库的数据。用户单击保存后,下拉列表将返回显示所选值的标签。

我的问题是,当您单击编辑按钮时,下拉列表永远不会出现。

这是代码:

.ASCX

<li>
    Campus
    <br />
    <span class="datainfoDropdown">
        <strong>
            <asp:Literal ID="CampusAttended" runat="server" ClientIDMode="Static"/>
        </strong>
        <asp:DropDownList ID="ProfileCampusDropDown" runat="server" ClientIDMode="Static" style="display:none;" ></asp:DropDownList>
    </span>
    <a href="#" class="editlinkDropdown">Edit Info</a>
    <a class="savebtnDropdown">Save</a>
</li>

Javascript

$(".editlinkDropdown").on("click", function (e) {
    e.preventDefault();
    var datasets = $(this).prevAll(".datainfoDropdown");
    var savebtn = $(this).next(".savebtnDropdown");
    datasets.each(function () {
        var theid = $(this).attr("id");
        var currval = $(this).text();
        var dropDown = $('#ProfileCampusDropDown').html();
        $('.datainfoDropdown').html(dropDown);
    });

    $(this).css("display", "none");
    savebtn.css("display", "block");
});

$(".savebtnDropdown").on("click", function (e) {
    e.preventDefault();
    var elink = $(this).prev(".editlinkDropdown");
    var datasets = $(this).prevAll(".datainfoDropdown");
    datasets.each(function () {
        var newid = $(this).attr("id");
        var einput = $("#" + newid + "-form");
        var newval = $('#ProfileCampusDropDown :selected').text();
        //einput.remove();
        $(this).html('<strong>' + newval + '</strong>');
    });

    $(this).css("display", "none");
    elink.css("display", "block");
});

如何让我的编辑按钮显示下拉列表?

4

2 回答 2

1

查看您的代码,您想要实现的目标并不是很清楚。我必须承认我没有看到 ids 和“-form”的意义。我肯定错过了什么。

无论如何,我想这应该做你所描述的(提供ProfileCampusDropDownsavebtnDropdown以 a 开头display:none;

    $(".editlinkDropdown").on("click", function (e) {
        e.preventDefault();
        $(this).prevAll(".datainfoDropdown").find("strong").hide();
        $('#ProfileCampusDropDown').show();
        $(this).hide();
        $(this).next(".savebtnDropdown").show();
    });

$(".savebtnDropdown").on("click", function (e) {
    e.preventDefault();
    var strong = $(this).prevAll(".datainfoDropdown").find("strong");
    strong.html($('#ProfileCampusDropDown :selected').text());
    strong.show();
    $('#ProfileCampusDropDown').hide();

    $(this).hide();
    $(this).prev(".editlinkDropdown").show();
});

希望这会有所帮助

于 2013-03-01T15:22:22.337 回答
0

我不知道您在 ASP.NET 中的什么位置,但很有可能您为 asp.net 控件设置的 ID 正在被服务器更改。

如果是这种情况,请设置控件的 CssClass 属性并使用$(".class")jQuery 的选择器。

于 2013-03-01T15:07:20.487 回答