2011-01-26 56 views
1

我在更新面板中的gridview中有一个dropdownlist控件(SourceDD),每当我点击下拉菜单时,OnSelectedIndexChanged事件就像它应该触发一样。但在此之前,它做了一个完整的回发,并贯穿整个Page_Load代码,这不是我想要的。基本上我希望它只运行OnSelectedIndexChanged事件,就是这样,不会导致完整的回发。在我的事件中,我只是根据它们在SourceDD中的选择来启用/禁用下一列(SymbolDD),所以在事件代码中没有什么特别的。如果有方法不要在包含gridview的updatepanel内完成一个完整的回发,请点击。非常感谢......GridView中的ASP.NET DropDownList控件引起SelectedIndexChanged事件的完全回发

<asp:UpdatePanel ID="TestsPanel" runat="server" Visible="true" UpdateMode="Conditional" EnableViewState="false" ChildrenAsTriggers="true"> 
       <ContentTemplate>     <asp:GridView ID="TestGridView" runat="server" Visible="true" CssClass="GridViewRows" AlternatingRowStyle-CssClass="TableRowEven" 
        AutoGenerateColumns="false"> 
        <HeaderStyle CssClass="TableHead" /> 
         <Columns>               
          <asp:TemplateField Headertext="Source"> 
            <ItemTemplate>         
             <asp:DropDownList runat="server" ID="SourceDD" AutoPostBack="true" OnSelectedIndexChanged="SourceDD_SelectedIndexChanged"> 
             </asp:DropDownList>                       
            </ItemTemplate>         
          </asp:TemplateField>         
          <asp:TemplateField Headertext="Symbol"> 
            <ItemTemplate>         
             <asp:DropDownList runat="server" ID="SymbolDD"> 
             </asp:DropDownList>            
            </ItemTemplate>         
          </asp:TemplateField>       
         </Columns>      
        </asp:GridView>       
        </ContentTemplate> 

回答

2

使用JavaScript/AJAX来处理该事件,如果你不想回发,或者尝试后面固定代码,妥善处理局部回传。

请点击以下链接: http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/ http://www.asp.net/ajax/tutorials/understanding-partial-page-updates-with-asp-net-ajax

+0

这就是我要求的,我如何避免在javascript或其他方式的完整回发?我是JavaScript新手,所以我不知道从哪里开始......谢谢! – TC1924 2011-01-26 23:23:19

1

我跟达斯汀同意。使用JavaScript,你必须把它放在你的控件GridViewRowDataBound事件上,这样你才能启用正确的控件。

喜欢的东西

RowDatabound(object sender, GridViewRowEventArgs e) 
{ 
    ((DropDownList)e.FindControl("SourceDD")).Attributes("onchange", <onchangelogic>); 
    //use something like "document.getElementById('" +(DropDownList)e.FindControl("SymbolDD")).ClientID + "').enabled = true;" 
    //or maybe it was .disabled = false.... 
} 
0

其实,有这个问题的解决方案。您可以将UpdatePanel添加到GridView的TemplateField的ItemTemplate,并将DropDownList添加到此UpdatePanel。然后为DropDownList“SelectedIndexChanged”事件添加AsyncPostBackTrigger。这可以确保发生在DropDownList的选定项目发生变化时的后发布是部分的(即整个页面不会刷新)。

相关问题