日期:2014-05-17  浏览次数:20551 次

GridView选中行就自动跳到第一行去了,每次还得拉滚动条!
由于数据过多,给GridView加了一个滚动条,但是只要选择下面的数据就会自动跳到第一行,还得往下拉滚动条才能看到下面的选中行....
我在GridView里面已经加了一个UpdatePanle,但是由于我的GridView有RowDataBound事件,可能还是会刷新,始终解决不了问题。
看了许多类似问题,也试了在页面里加MaintainScrollPositionOnPostback="true",但还是没有效果。也看了许多js方法,但是看不懂,不知道具体该怎么做,哪些代码放哪里...
求高手解决!在此先谢过了....

------解决方案--------------------
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
     <ContentTemplate>
        <asp:GridView ID="gvzh" runat="server" AutoGenerateColumns="False" DataKeyNames="RecID" EnableViewState="false" OnRowDataBound="gvzh_RowDataBound" ShowFooter="True" SkinID="gv1">
            <Columns>
                <asp:BoundField DataField="CustomerName" HeaderText="客户名称" />
                <asp:BoundField DataField="HeadLinkManName" HeaderText="联系人" />
            </Columns>
            <FooterStyle Height="20px" />
        </asp:GridView>
    </ContentTemplate>
    <Triggers>
       <asp:AsyncPostBackTrigger ControlID="btFind" EventName="Click" />
    </Triggers>       
    </asp:UpdatePanel> 
这是我的gridview,然后RowDataBound绑定:  
  protected void gvzh_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Visible = false;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("id", e.Row.Cells[0].Text);
            e.Row.Attributes.Add("onclick", "GetRecID('" + e.Row.Cells[0].Text + "');");//单机
            e.Row.Attributes.Add("ondblclick", "ChkMod(700,424,'Sell/SellDetail.aspx','销售明细');");//双击
            e.Row.Attributes.Add("onmouseover", "this.style.cursor='default';");
         }
     }

其中的GetRecID,ChkMod方法是js函数