是否可以在gridview中回发到特定定义的卷?基本上,我有一个gridview,其中有一个下拉列表。当用户从下拉列表中选择一个选项时,我希望回发返回到同一列。 HEre是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);
如何取得成果?
答案 0 :(得分:1)
将ScrollIntoView
JS命令与下拉列表的客户端ID结合使用。将以下代码添加到下拉列表的OnSelectedIndexChanged
事件:
ClientScript.RegisterStartupScript(this.GetType(), "hash", "document.getElementById('" + ((DropDownList)sender).ClientID + "').scrollIntoView();", true);
在回发时,它会将当前点击的下拉列表滚动回视图。
或甚至尝试像
那样简单明了的事情((DropDownList)sender).Focus();