2013-07-30 48 views
0

是否有可能回發到gridview中特定定義的卷?從本質上講,我有一個gridview,它有一個下拉列表。當用戶從下拉列表中選擇一個選項時,我希望回發回到同一列。這裏是GridView控件:回發到特定的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

東西,你有沒有考慮過在您的網格分頁? –

+0

我有,它的使用方式,它不會是理想的。 – endr3am

回答

1

使用ScrollIntoView JS命令與下拉的客戶端ID一起使用。下面的代碼添加到您的下拉的OnSelectedIndexChanged事件:

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

在回發將當前滾動下拉點擊回視圖。

OR甚至嘗試爲簡單明瞭的

((DropDownList)sender).Focus();