本文介绍了如何动态地从一个ListBox复制选定listItems中的一个DropDownList,并让它在网页中正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是codebehind看起来像它的工作原理,并根据调​​试器,它(没有错误或异常)。不幸的是它实际上并没有对我的asp.net web表单的网页工作,DROPDOWNLIST实际上并没有与ListBox的选定项目填充。这确实应该是简单的,但显然不是。

My problem is the codebehind looks like it works and according to the debugger, it does (no errors or exceptions). Unfortunately it does not actually work on my asp.net webforms webpage, the DropdownList does not actually populate with the selected items of the ListBox. This really should have been simple, but apparently not.

我的研究说,列表框和DropDownList的应该是UpdatePanel的内部,和儿童作为触发器需要设置为true,并且使用ScriptManager的帮助下,将拦截回传请求,只做局部页面更新。然而,当没有工作,我试图直接调用updatepanels.update()方法,这也不能工作。

My research said that the Listboxes and DropDownList should be inside of UpdatePanels, and children as triggers needed to be set to true, and with the help of the ScriptManager it would intercept postback requests and do only partial page updates. Nevertheless when that did not work I tried calling the updatepanels.update() method directly and this did not work either.

下面是我的C#code。

Here is my C# code.

  protected void GroupList_SelectedIndexChanged(object sender, EventArgs e)
    {
        updategroupEntry();
    }

    protected void updategroupEntry() 
    {
        EnterAGroup.Items.Clear();
        foreach (ListItem li in GroupList.Items)
        {
            if (li.Selected)
            {
                EnterAGroup.Items.Add(li);
            }
        }
        OptionsUpdater.Update();
        OverallUpdater.Update();
    }

在我的code我使用嵌套的更新面板,整体/周围一个显示在这里,我还包含了一个在我的第二个DROPDOWNLIST结束标记。这是第一个code段。

In my code I use nested update panels, the overall/surrounding one is shown here, I have also included the closing tags for the one in my second DropdownList. Here is the first code segment.

<asp:UpdatePanel ID="OverallUpdater" UpdateMode="Conditional" runat="server" ChildrenAsTriggers="true">
       <ContentTemplate>

 //irrelevant code omitted

                <asp:Listbox AutoPostback="True" ID="GroupList" runat="server" Width="166px"  SelectionMode="Multiple" OnSelectedIndexChanged="GroupList_SelectedIndexChanged" DataSourceID="GroupSource" DataTextField="GroupName" DataValueField="GroupID">
                </asp:Listbox>
                <asp:SqlDataSource ID="GroupSource" runat="server"
                     ConnectionString="<%$ ConnectionStrings:ACESConnectionString %>" 
                    SelectCommand="SELECT [GroupName], [GroupID] FROM [PrimaryGroup] ORDER BY [GroupName]"></asp:SqlDataSource>

 //more code omitted

              <%--End of Options Panel --%>
                    </asp:Panel>
                </ContentTemplate>
              </asp:UpdatePanel> 

        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="viewapps" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="UpdateButton" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="FilterButton" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>  

在我的aspx页面我有这个code在我的DropDownList。

In my aspx page I have this code around my DropDownList.

    <asp:UpdatePanel ID="OptionsUpdater" UpdateMode="Conditional" runat="server"  ChildrenAsTriggers="true" ViewStateMode="Enabled"> 
       <ContentTemplate>

  //other code omitted for brevity.

          <asp:TableCell>
             <asp:DropDownList runat="server" ID="EnterAGroup" BackColor="PaleVioletRed" AutoPostBack="true"></asp:DropDownList>
          </asp:TableCell>

 //other code omitted for brevity.

    </ContentTemplate>
 </asp:UpdatePanel> 

所以,codebehind说,它的作品,但它只是没有更新的网页。我如何得到它才能正常工作?

So the codebehind says its works, but it just isn't updating on the webpage. How do I get it to work correctly?

我会很高兴应要求给予更多的code。
另外,如果你需要测试code,我建议2列一些表格替换为您自己的SqlDataSource。

I will be glad to give more code upon request.Also, if you need to test the code, I recommend substituting your own SqlDataSource with 2 columns from some table.

更新
我曾尝试切里安中号保罗的想法及其生产奇怪的结果那里只有当我选择从该组的所有项目,但中途的工作不只是少数。

UpdateI have tried Cherian M Paul's idea and its producing strange results where it only half-way works when I select all items from the group but not only a few.

下面是半路时被选中的所有组。

Here is it halfway working when all groups are selected.

下面是当只有一些被选中它不工作的图像。

Here is an image of it not working when only some are selected.

更新

在进一步调查中有一个点,有一个断开并点击网页不再到达codebehind。

After further investigation there is a point where there is a disconnect and clicks on the webpage no longer reach the codebehind.

我有这种脱节的视频。基本上,在最后没有点击量就会触发事件在我的codebehind。

I have a video of this disconnection. basically, at the end no amount of clicks will trigger the events in my codebehind.

推荐答案

我相信,您需要添加触发ID为第二的UpdatePanel为 OptionsUpdater 。类似你做的第一个方法。

I believe that, you need to add the trigger for the second UpdatePanel with ID as OptionsUpdater. Similar to the way you did for the first one.

&LT; ASP:AsyncPostBackTrigger控件ID =群组列表
事件名称=GroupList_SelectedIndexChanged/&GT;

请尝试更新的HTML。也有没有局部更新,而使用更新面板还,asp.net其实做所有的工作,但只有一部分页面进行更新和用户感觉就像是做在后端的一些事情。

Please try updating the html. Also there is no partial update, while using update panel also, asp.net actually does all the work , but only a part of the page is updated and user feels like it is doing some thing on back end.

我可以建议你实现这类使用jQuery的任务。

Can I suggest you to achieve these kind of tasks using jQuery.

这篇关于如何动态地从一个ListBox复制选定listItems中的一个DropDownList,并让它在网页中正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 08:59