0

是否可以回发到网格视图中特定定义的滚动?本质上,我有一个gridview,其中有一个下拉列表。当用户从下拉列表中选择一个选项时,我希望回发返回到同一列。这是网格视图:

 <asp:GridView ID="viewThemeTypeAssociationsGridView" runat="server" AutoGenerateColumns="False"
                                BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" DataKeyNames="PK_Theme"
                                CellPadding="3" CellSpacing="2" DataSourceID="SqlDataSource6" OnRowDataBound="viewThemeTypeAssociationsGridView_OnRowDataBound">
                                <Columns>
                                    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                                    <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
                                    <asp:TemplateField HeaderText="Choose Theme Type">
                                        <ItemTemplate>
                                            <asp:DropDownList ID="chooseThemeTypeDropDown" runat="server" DataTextField="Type" DataValueField="PK_ThemeType" AutoPostBack="true" DataSourceID="SqlDataSource9" CssClass="dropDownList" OnDataBound="chooseThemeTypeDropDown_OnDataBound" Visible="false" OnSelectedIndexChanged="chooseThemeTypeDropDown_OnSelectedIndexChanged">
                                            </asp:DropDownList>
                                            <asp:SqlDataSource ID="SqlDataSource9" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                                                SelectCommand="SELECT [Type], [PK_ThemeType] FROM [ThemeType] WHERE [Deleted] = 0 ORDER BY [Type] ASC">
                                            </asp:SqlDataSource>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                                <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                                <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                                <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                                <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                                <SortedAscendingCellStyle BackColor="#FFF1D4" />
                                <SortedAscendingHeaderStyle BackColor="#B95C30" />
                                <SortedDescendingCellStyle BackColor="#F1E5CE" />
                                <SortedDescendingHeaderStyle BackColor="#93451F" />
                            </asp:GridView>
                            <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                                SelectCommand="SELECT [Theme].[PK_Theme], [Theme].[Name], [ThemeType].[Type] FROM [Theme] LEFT OUTER JOIN [ThemeType] ON [Theme].[ThemeTypeId] = [ThemeType].[PK_ThemeType] JOIN [ProductTheme] ON [ProductTheme].[ThemeId]=[Theme].[PK_Theme] WHERE ProductTheme.ProductID LIKE @productParam AND ProductTheme.ThemeId = Theme.PK_Theme AND COALESCE([THEME].[THEMETYPEID], 'null') LIKE @assignedParam GROUP BY [Theme].[Name], [ThemeType].[Type], [Theme].[PK_Theme] ORDER BY CASE WHEN [ThemeType].[Type] IS NULL THEN 0 ELSE 1 END, [Theme].[Name]">
                                <SelectParameters>
                                    <asp:QueryStringParameter Name="productParam" Type="String" />
                                    <asp:QueryStringParameter Name="assignedParam" Type="String" />
                                </SelectParameters>
                            </asp:SqlDataSource>

此外,这是我目前正在做的回发,但它只是到了可能有数百行长的 gridview 的顶部。

 ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#viewPanelPostBack';", true);

我怎样才能得到所取得的成果?

4

1 回答 1

1

ScrollIntoViewJS 命令与下拉列表的客户端 ID 结合使用。将以下代码添加到您的下拉OnSelectedIndexChanged事件中:

ClientScript.RegisterStartupScript(this.GetType(), "hash", "document.getElementById('" + ((DropDownList)sender).ClientID + "').scrollIntoView();", true);

在回发时,它会将当前单击的下拉列表滚动回视图。

或者甚至尝试一些简单明了的东西

((DropDownList)sender).Focus();
于 2013-07-30T16:17:51.543 回答