0

我正在尝试将 2 个下拉列表添加到弹出窗口中。但我遇到了麻烦。

我有一个名为“showMessage”的函数,它创建一个弹出窗口。

所以:showMessage(“你好”);将创建一个带有“hello”字样的弹出窗口。现在我的问题是如何添加 2 个下拉列表。我尝试使用 2 个下拉列表创建一个 div,然后执行 showMessage(document.getElemenyBiId(ddl)); 但我知道这是不对的。

这是我的“showMessage”功能:

function showMessage(msg, title, onOk) {
if (title === undefined)
    title = "";

if (onOk === undefined)
    onOk = function () {
        $(this).dialog('close');
    }

$('<div>').dialog({
    title: title,
    height: 'auto',
    width: '250',
    open: function () {
        $(this).html(msg);
    },
    buttons: {
        Ok: onOk
    },
    close: function () {
        $(this).remove();
    }
});

}

这是我的下拉列表 div:

<div id="newExpenseTypeDialog" style="display:none;">
        <label>Select new CaseFile:</label>
        <asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" />
</div>

javascript函数我必须在我试图让一个弹出窗口加载2个下拉列表然后让用户从两者中选择一个id然后让它将2个值传递给函数来做我想要它做的事情。

function moveCasefile(isMovePossible) {
        //var newCaseFileID;
        //var oldCaseFileID;
         //this area I am trying to get the popup to happen and get the input from the user via dropdownLists.
        if (newCaseFileID || oldCaseFileID) {
            //alert(ans);

            var selectedExpensesList = getSelectedExpenseIDs();
            if (selectedExpensesList.length > 0) {
                $.ajax({
                    type: "POST",
                    //url: "/Tasks/ViewTasks.aspx/deleteTasksAndLinkedItems",
                    url: '<%=ResolveUrl("~/Expenses/ViewExpenses.aspx/moveNewCaseFile")%>',
                    data: "{'MoveCaseFile' : '" + isMovePossible + "','ExpId': ['" + selectedExpensesList.join('\',\'') + "'],'newCaseFileID': '" +
                    newCaseFileID + "', 'oldCaseFileID': '" + oldCaseFileID + "'}",
                    //dataaaaaa`

我的 div 与 DropDownLists:

<div id="newExpenseTypeDialog" style="display:none;">
        <label>Select new CaseFile:</label>
        <asp:DropDownList runat="server" ID="ddlCaseFiles" DataSourceID="dsMyCaseFiles" DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" />
        <asp:DropDownList runat="server" ID="ddlCaseFiles2" DataSourceID="dsMyCaseFiles" DataTextField="Display" DataValueField="FileID" OnPreRender="ddl_PreRender" Width="524px" />
</div>

我的 DropdownLists 数据源:

<asp:SqlDataSource ID="dsMyCaseFiles" runat="server" ConnectionString="<%$ ConnectionStrings:OSCIDConnectionString %>" ProviderName="System.Data.SqlClient" SelectCommand="p_CaseFiles_ListActiveCaseFilesAssignedTo" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:SessionParameter Name="InvestigatorID" SessionField="InvestigatorID" />
        <asp:SessionParameter Name="AssignedTo" SessionField="InvestigatorID" />
    </SelectParameters>
</asp:SqlDataSource>

还有我的“pre_render”代码隐藏:

 protected void ddl_PreRender(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    try
    {
        if (ddl.Items[0].Value != "-1")
            ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
    }
    catch
    {
        ddl.Items.Insert(0, new ListItem("--Select--", "-1"));
    }
}
4

1 回答 1

1

您可以像这样在 Select Index Change 上调用该函数:-

<asp:DropDownList ID="ddl" runat="server"  AutoPostBack="true" onchange="javascript:showMessage();" OnSelectedIndexChanged="ddl_SelectedIndexChanged"></asp:DropDownList>

在 DropDown Databound 事件中,您可以写为:

 protected void ddl_DataBound(object sender, EventArgs e)
{
    ddl.Items.Insert(0, new ListItem("Select new CaseFile:", "-1"));
}

要获得价值:-

var e = document.getElementById("ddl");
var strUser = e.options[e.selectedIndex].value;

如果您选择下拉文本:-

var e = document.getElementById("ddl");
var strUser = e.options[e.selectedIndex].text;
于 2012-09-20T15:27:18.677 回答