1

我动态创建了一些 RadCombobox。用户选择后,我尝试从 RadComboBox 获取值。但我找不到控制。

这是我的代码:

ASP.NET:

    <asp:Panel ID="pnlErsteMenuesAnlegenSchritt3" runat="server">
        <ul runat="server" id="MenuAusMenuPunktenZusammengesetzt" class="MenuColletionPos">
        </ul>

        <telerik:RadButton ID="rtbnMenuElementeHrefEingabeVerarbeiten" runat="server" Text="Weiter" OnClientClicking="CollectMenuElementeWithHref"></telerik:RadButton>
    </asp:Panel>

VB.net:

    Public Sub MenuHrefAnlegen(ByVal endVal As Integer, ByVal strArrQuerystring As Array)

    Dim width As String = "width:199px;"
    Dim count As Integer = 1
    Dim i As Integer
    Dim startval As Integer
    startval = 1
    For i = startval To endVal
        'erzeuge menü element

        Dim combo As New RadComboBox()
        combo.ID = "rcbHrefAuswaehlen" & count
        combo.EnableLoadOnDemand = True
        combo.Skin = "Metro"
        combo.Items.Insert(0, New RadComboBoxItem("Über uns", String.Empty))
        combo.Items.Insert(1, New RadComboBoxItem("Baufinanzierung", String.Empty))
        combo.Items.Insert(2, New RadComboBoxItem("Denkmal-Immobilien", String.Empty))
        combo.Items.Insert(3, New RadComboBoxItem("Photovoltaik", String.Empty))
        combo.Items.Insert(4, New RadComboBoxItem("Assekuranz", String.Empty))
        combo.Items.Insert(5, New RadComboBoxItem("Kontaktseite", String.Empty))
        combo.Items.Insert(6, New RadComboBoxItem("Impressum", String.Empty))
        combo.Items.Insert(7, New RadComboBoxItem("Benutzerdefinierte Seite", String.Empty))

        Dim hfMenuElement As New HiddenField
        hfMenuElement.ID = "hfMenuElement" + count.ToString()
        hfMenuElement.Value = strArrQuerystring(count)

        MenuAusMenuPunktenZusammengesetzt.Controls.Add(New LiteralControl("<li class=""floatKill""><a href=""#"" id=""hrefm" & count & """ runat=""server"" onmouseover=""menuov('menuleft" & count & "', 'menupuffer" & count & "', 'menuright" & count & "');"" onmouseout=""menuovf('menuleft" & count & "', 'menupuffer" & i & "', 'menuright" & count & "');""><div id=""menuleft" & count & """ class=""menu_left""></div><div id=""menupuffer" & count & """ class=""menu_puffer"" style=""" & width & """>" & strArrQuerystring(count) & "</div><div id=""menuright" & count & """ class=""menu_right""></div></a><div class=""pfeil links"" style=""margin-left:15px;margin-top:8px;""></div><div class=""pfeil links"" style=""margin-top:8px;""></div><div class=""pfeil links"" style=""margin-right:15px;margin-top:8px;""></div></li>"))
        MenuAusMenuPunktenZusammengesetzt.Controls.Add(combo)
        MenuAusMenuPunktenZusammengesetzt.Controls.Add(hfMenuElement)

        count += 1
    Next

End Sub

jQuery:

           function CollectMenuElementeWithHref(sender, eventArgs) {
            var VID = $('input[id$=hfVermittlerID]').val();
            var obj = { ID: VID };
            for (var i = 1; i < 9; i++) {
                var hfVal = $('[id$=hfMenuElement' + i + ']').val();

                //At this point i get Null back
                var combo = $find("<%= rcbHrefAuswaehlen" + i + ".ClientID %>");
                var item = combo.get_items().getItem(2);

                if (hfVal) {
                    obj["pa" + i] = hfVal
                    obj["href" +1] = item.get_text()
                }
            }
            eventArgs.set_cancel(true);
            window.location.href = 'VermittlerBearbeiten.aspx?' + $.param(obj);
        }

我总是得到 Null 回来。

var combo = $find("<%= rcbHrefAuswaehlen" + i + ".ClientID %>");

这与我如何创建此控件有关吗?我希望有人能帮助我。

谢谢大家阅读:)

4

2 回答 2

1

要找到 RadCombobox 。请检查您是否在创建控件后调用 javascript

var combo = $find("<%= rcbHrefAuswaehlen" + i + ".ClientID %>");//u r doing right

或者

var combo = $("[id$='rcbHrefAuswaehlen''"+ i +"']");

帮助

于 2013-10-18T10:23:41.780 回答
1

请尝试使用以下代码片段。

 var combo = $find("rcbHrefAuswaehlen" + i);

完整的演示代码

ASPX

<html>
<head runat="server">
    <title></title>
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script>

            function CollectMenuElementeWithHref() {
                for (var i = 0; i < 3; i++) {
                    var combo = $find("rcbHrefAuswaehlen" + i);
                    var item = combo.get_items().getItem(1);
                }
            }

        </script>
    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <asp:Panel ID="pnlCombo" runat="server"></asp:Panel>
            <telerik:RadButton ID="rtbnMenuElementeHrefEingabeVerarbeiten" runat="server" Text="Weiter" OnClientClicking="CollectMenuElementeWithHref"></telerik:RadButton>
        </div>
    </form>
</body>
</html>

ASPX.CS

protected void Page_Init(object source, System.EventArgs e)
{
    GenerateCombo();
}


protected void GenerateCombo()
{
    for (int i = 0; i < 3; i++)
    {
        RadComboBox r1 = new RadComboBox();
        r1.ID = "rcbHrefAuswaehlen" + i;
        r1.Items.Add(new RadComboBoxItem() { Text = "a", Value = "b" });
        r1.Items.Add(new RadComboBoxItem() { Text = "aa", Value = "bb" });
        r1.Items.Add(new RadComboBoxItem() { Text = "aaa", Value = "bbb" });
        pnlCombo.Controls.Add(r1);
    }
}

如果我不明白你的问题,请告诉我。

于 2013-10-18T10:38:12.437 回答