Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除所有Gridview项时,不会填充jquery Selected下拉列表_Gridview_Jquery Chosen - Fatal编程技术网

删除所有Gridview项时,不会填充jquery Selected下拉列表

删除所有Gridview项时,不会填充jquery Selected下拉列表,gridview,jquery-chosen,Gridview,Jquery Chosen,当用户想要添加到表中时,我在FooterTemplate的Gridview中有一个jquery Selected下拉框。 如果表中没有项目,下拉列表将正确显示用户可以选择的列表。但是,如果用户删除表中的所有项,则EmptyDataTemplate中的下拉列表不会显示任何项 我相信我必须更新所选的下拉列表,但它不起作用 这是我的标记: <asp:GridView ID="DelegateInfoGridView" runat="server" AutoGenerateCol

当用户想要添加到表中时,我在FooterTemplate的Gridview中有一个jquery Selected下拉框。 如果表中没有项目,下拉列表将正确显示用户可以选择的列表。但是,如果用户删除表中的所有项,则EmptyDataTemplate中的下拉列表不会显示任何项

我相信我必须更新所选的下拉列表,但它不起作用

这是我的标记:

<asp:GridView ID="DelegateInfoGridView" runat="server" 
        AutoGenerateColumns="false" Caption="Delegate Information" 
        CaptionAlign="Top" CssClass="grid" RowStyle-Wrap="true" 
        HorizontalAlign="Left" ShowFooter="true" 
        AllowPaging="true" PageSize="5"  ShowHeaderWhenEmpty="false" onrowediting="DelegateInfoGridView_RowEditing" 
        onrowcancelingedit="DelegateInfoGridView_RowCancelingEdit" onrowdeleting="DelegateInfoGridView_RowDeleting" 
        onrowupdating="DelegateInfoGridView_RowUpdating" 
        ondatabound="DelegateInfoGridView_DataBound" 
        onrowcommand="DelegateInfoGridView_RowCommand">
        <Columns>
             <asp:TemplateField HeaderText="Recipient ID">
                <ItemTemplate>
                    <asp:Label ID="deligvLblRecipientID" runat="server" Text='<%# Bind("RecipientID") %>'></asp:Label>
                </ItemTemplate>
             </asp:TemplateField>

             <asp:TemplateField HeaderText="Delegate" ItemStyle-Wrap="false"> 
                <ItemTemplate>
                    <asp:Label ID="deligvLblRecipientName" runat="server" Text='<%# Bind("RecipientName") %>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="deligvDDLRecipientName" runat="server" 
                                        data-placeholder="Choose delegate…" class="chosen-single">
                    </asp:DropDownList>
                </FooterTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="Active"> 
                <ItemTemplate>
                    <asp:Label ID="deligvLblActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'></asp:Label>
                </ItemTemplate>         
                 <EditItemTemplate>
                    <asp:DropDownList ID="deligvDDLActive" runat="server" Text='<%# (Boolean.Parse(Eval("Active").ToString())) ? "Yes" : "No" %>'>
                        <asp:ListItem>Yes</asp:ListItem>
                        <asp:ListItem>No</asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate> 
                <FooterTemplate>
                    <asp:DropDownList ID="deligvDDLActiveInsert" runat="server">
                        <asp:ListItem Selected="True">Yes</asp:ListItem>
                        <asp:ListItem>No</asp:ListItem>
                    </asp:DropDownList>
                </FooterTemplate>                         
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Action" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center">
                 <ItemTemplate>
                    <asp:Button ID="deligvEditButton" runat="server" CausesValidation="False" CommandName="Edit" 
                                Text="Edit" CssClass="gridActionbutton">
                    </asp:Button>
                    &nbsp;<asp:Button ID="deligvDeleteButton" runat="server" CausesValidation="False" CommandName="Delete" 
                                Text="Delete" CssClass="gridActionbutton"  OnClientClick="return confirm('Are you sure you want to delete this Delegate Information?')" >
                    </asp:Button>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Button ID="deligvUpdateButton" runat="server" CausesValidation="False" CommandName="Update" 
                                    Text="Update" CssClass="gridActionbutton"></asp:Button>
                    &nbsp;<asp:Button ID="deligvCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" 
                                    Text="Cancel" CssClass="gridActionbutton"></asp:Button>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:Button ID="deligvAddButton" runat="server" CommandName="Add" Text="Add Delegate" Width="90%" CausesValidation="false" 
                                CssClass="gridActionbutton">
                    </asp:Button>
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            <tr>
                <th>Recipient ID</th>
                <th>Delegate</th>
                <th>Active</th>
                <th>Action</th>
            </tr>
            <tr> 
                <td colspan="4" style="text-align:center;">
                    No Delegates were found for you. Delegates can be added by clicking the 'Add Delegate' Button.
                </td> 
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:DropDownList ID="deligvDDLRecipientName" runat="server" 
                                        data-placeholder="Choose delegate…" class="chosen-single">
                    </asp:DropDownList>
                </td>
                <td>
                     <asp:DropDownList ID="deligvDDLActiveInsert" runat="server">
                        <asp:ListItem Selected="True">Yes</asp:ListItem>
                        <asp:ListItem>No</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:Button ID="deligvAddButton" runat="server" CommandName="Add" Text="Add Delegate" Width="90%" CausesValidation="false" 
                        CssClass="gridActionbutton">
                    </asp:Button>
                </td>
            </tr>
        </EmptyDataTemplate>
     </asp:GridView>
这是我的javascript:

 <script type="text/javascript">
    $(document).ready(function () {
        //Configure the DropDownBox using the 'chosen' jquery plugin
        $(".chosen-single").chosen({
            search_contains: true,
            no_results_text: "Sorry, no match!"                           
        });
    });

    $('#deligvAddButtonEmpty').click(function () {
        $(".chosen-single").chosen().val('').trigger("chosen:updated");
    });

</script>
但当网格为空时,下拉列表仍然为空

更新

我试图使用Firebug调试javascript,但似乎没有调用.click函数。至少,当我在函数中放置断点时,它不会像在document.ready函数中那样停止。 我使用的是母版页,并且有ClientIDMode='Static'属性,但可能没有正确定义'selector'

更新

不是在单击“添加按钮”时,而是在单击“删除按钮”且网格中没有其他项目时,所选下拉列表不会刷新。 但是,我似乎无法为按钮触发click事件。这是我的jquery单击功能:

 $(document).on("click", "input[id$=deligvDeleteButton]", function () {
        alert("Delegate delete button clicked");
    });
$("input[id$=deligvDeleteButton]").click(function () {
              $("input[id$=deligvDDLRecipientName]").val('').trigger("chosen:updated");
            });
更新 至少,现在点击功能被触发了。。。 我向正在访问的控件中添加了ClientIDMode-“Static”,并将“click”函数放在document.ready函数中。但是,更新不会将列表添加到下拉列表中。这就是功能:

 $(document).on("click", "input[id$=deligvDeleteButton]", function () {
        alert("Delegate delete button clicked");
    });
$("input[id$=deligvDeleteButton]").click(function () {
              $("input[id$=deligvDDLRecipientName]").val('').trigger("chosen:updated");
            });
更新

我不知道这是否是问题所在,但在GridView或EmptyDataTemplate中,这可能与jquery脚本中的控件ID有关。对于GridView或EmptyDataTemplate中的下拉列表,我保持相同的ID。在后面的代码中,我通过确定FooterControl是否为null来确定使用哪个控件。那么其余的C代码是相同的,因为ID是相同的。但是,在javascript中,如果ID相同,这可能是一个问题

如何识别EmptyDataTemplate中的控件而不是Gridview中的控件

更新

我不知道这是否是问题所在,但在GridView或EmptyDataTemplate中,这可能与jquery脚本中的控件ID有关。对于GridView或EmptyDataTemplate中的下拉列表,我保持相同的ID。在后面的代码中,我通过确定FooterControl是否为null来确定使用哪个控件。那么其余的C代码是相同的,因为ID是相同的。但是,在javascript中,如果ID相同,这可能是一个问题

如何识别EmptyDataTemplate中的控件而不是Gridview中的控件

我使用以下javascript获取两个下拉控件的ID并更新它们,下拉列表仍然没有填充:

 $("input[id$=deligvDeleteButton]").click(function () {               
            $("[id*='deligvDDLRecipientName']").each(function () {
                alert($(this).attr('id'));
                $(this).val("").trigger("chosen:updated");
            });            
        });
此警报显示ID。一个是“DeligvdlRecipientName”,另一个是DeligvdlRecipientName_。我用.trigger函数更新了它们,但列表仍然没有填充。

我发现了这一点。。。 万一有人有这个问题

它与选择的插件无关。 这是我确定FooterControl是否实例化的方式。我检查了空值。但当用户删除所有行时,FooterControl不为null,但仍需要使用EmptyTemplateData控件。 因此,我没有检查null,而是检查行数>0。 成功了