【问题标题】:how to get value from dropdownlist which in ModalPopupExtender如何从 ModalPopupExtender 中的下拉列表中获取价值
【发布时间】:2012-04-30 16:37:05
【问题描述】:

我有一个 modalpopup,它会在页面启动时自动显示。我在 Page_Load 事件中这样做。

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitiallizeAll();
        }
    }

    private void InitiallizeAll()
    {
        ModalPopupExtender1.Show();
    }

在 aspx 方面,我在 modalpopup 上有一个下拉列表,但索引始终将零发布到 javascript 代码。

    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"           
                            TargetControlID="lnkPopup"
                            PopupControlID="panEdit" 
                            BackgroundCssClass="modalBackground" 
                            OkControlID="btnGonder"
                            OnOkScript="onOk()">
    </asp:ModalPopupExtender>
<asp:Panel ID="panEdit" runat="server" Height="180px" Width="400px" CssClass="modalPopup">
    <table width="100%">
        <tr>
            <td class="labelCell">
                <asp:Label ID="lblBolge" Text="Bölge" runat="server" />
            </td>
            <td>
                <asp:DropDownList ID="ddlIl" runat="server" 
                                  AutoPostBack="False" 
                                  DataTextField="Isim"
                                  DataValueField="Id" 
                                  DataSourceID="ObjectDataSource1" 
                                  Width="176px">
                </asp:DropDownList>
                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                                      SelectMethod="GetAllIl"
                                      TypeName="ERK.Lasos.Business.CustomEntities.Il">
                    <SelectParameters>
                        <asp:QueryStringParameter DefaultValue="0" 
                                                  Name="ilId" 
                                                  QueryStringField="bolge"
                                                  Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
            </td>
        </tr> 
    </table>
    <br />
    <asp:Button ID="btnGonder" runat="server" Text="Devam Et" />
</asp:Panel>
<a id="lnkPopup" runat="server">Show Popup</a>

这是我的 javascript 代码

        <script type="text/javascript">
        function onOk() {
        var e = document.getElementById("ddlIl");
        var selectedIlId = e.options[e.selectedIndex].value;
        window.location = "/Pages/AnaSayfa/LasosAnaSayfa.aspx?bolge=" + selectedIlId;
        }
        </script>

但我总是得到 selectedIlId 是“0”。值不会改变我从下拉列表中选择的任何内容

【问题讨论】:

    标签: asp.net drop-down-menu modalpopupextender


    【解决方案1】:

    首先,您应该检查您是否获得了良好的选择索引。 :

    暂时将var selectedIlId = e.options[e.selectedIndex].value; 替换为var selectedIlId = e.selectedIndex;

    如果没问题,您应该通过确保 Id 字段正确来检查您的数据源,最简单的方法是将 DataTextField="Id" 设置为您的 DropdownList 并检查其中显示的值。

    【讨论】:

    • 感谢回复,我使用代码隐藏 button_click() 事件解决了这个问题。 javascript 解决方案对我不起作用
    • 这不是一个帮助论坛,提出问题并仅仅说你解决了你的问题不是推荐的行为。如果您继续走这条路,您可能会被否决,并且您的帖子将被忽略。
    • 很抱歉,但我不知道在这种情况下我应该怎么做。我只是想回答你的建议
    猜你喜欢
    • 2020-08-11
    • 1970-01-01
    • 2013-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    相关资源
    最近更新 更多