日期:2014-05-18  浏览次数:20390 次

级联DropDownList,引发刷新页面侯GRIDVIEW内数据定位问题
HTML code
 <asp:UpdatePanel ID="formUpdatePanel" runat="server">
                <ContentTemplate>
<asp:GridView ID="itemGridView" runat="server">
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
                </ContentTemplate>
                <Triggers>
                </Triggers>
            </asp:UpdatePanel>



目标效果是:DropDownList1的选择项目变化之后执行DropDownList1_SelectedIndexChanged()给DropDownList2重新绑定数据源,导致刷新,GRIDVIEW和DropDownList同在一个UpdatePanel中,所以虽然GRIDVIEW内数据不变,但如果之前我把GRIDVIEW的滚动条拉到下面了然后改变DropDownList1的选项,由于刷新了UpdatePanel会导致GRIDVIEW的下拉条回到最顶部

如果是BUTTON导致的可以用OnClientClick去执行JS保存gridviewDiv.scrollTop;的值给隐藏控件然后后台再调JS把下拉条调整回来,但是DropDownList没有这类属性,有没有好点的办法解决这个问题?

------解决方案--------------------
为什么不再增加一个UpdatePanel,将GridView和DropDownList分开
------解决方案--------------------
up
------解决方案--------------------
所以虽然 GRIDVIEW内数据不变

========

那么 DropDownList2 和 GrdiView 最好不要在一个 UpdatePanel 中,你可以用 UpdatePanel.Update() 方法来控制某个 updatepanel 刷新


如果是BUTTON导致的可以用OnClientClick去执行JS保存gridviewDiv.scrollTop;的值给隐藏控件然后后台再调JS把下拉条调整回来,但是DropDownList没有这类属性,有没有好点的办法解决这个问题?

=============

DropDownList.Attributes["onchange"] = <<your js>>;
------解决方案--------------------
用二个UPDATEPANEL,有表格的那一个设置事件触发即可
------解决方案--------------------
帮顶~
------解决方案--------------------
没看明白,能说的简单点吗?
------解决方案--------------------

1,在页面里写js事件保存gridviewDiv.scrollTop的值给隐藏控件然后后台再调JS把下拉条调整回来
这个你应该会了就不写了。
2.在你的DropDownList1_SelectedIndexChanged()事件里,写
String scriptText = "<script language='javascript'>你的js方法;</script>";
ClientScript.RegisterStartupScript(this.GetType(), "ConfirmSubmit", scriptText);

然后就可以在后台触发你的js事件了,应该可以保存你需要的位置。