title: GridView destroy tab order
body: <p>I have a user control that has two dropdownlists, four textboxes and a gridview in said order. I want the focus to move in this order as tab key is pressed. </p>
  
  <p>I have tabindex property of each control set in sequence (1005, 1010, 1015 ...) except the gridview whose tabindex property is not set to anything. </p>
  
  <p>At page_load I am setting focus to the first dropdownlist.</p>
  
  <p>When page is loaded, focus is on the first dropdownlist, as desired. Then when tab is pressed focus moves to the next dropdownlist, as desired. The problem is when the tab is pressed at this stage, now instead of moving to the first textbox (which has tabindex set to 1015), the focus is moved on the gridview. Note that the gridview do not have its tabindex set to anything. When tab is pressed now, the focus is moved on other user controls on the page, that is, totally out of the discussed user control. Then after several key presses user control do come back to the user control and then move in desired order, that is, first dropdownlist, then second dropdownlist, then first textbox, then second textbox, then third textbox, then fourth textbox. After this it skip the gridview altogether and move to controls which are at the master page. </p>
  
  <p>So, when page is loaded, tab is moving in a different order than what it do once cycle of tabs is completed, that is, all controls are focused.</p>
  
  <p>If I move focus to the first textbox by using mouse click, then press tab then focus is moved to the second textbox as desired, then to third textbox as desired, then to fourth textbox as desired.</p>
  
  <p>I am using two user controls in the page, one of which is discussed above, plus a control directly on page. There are some controls in master page too.</p>
  
  <p>No server or client side event handling happens when tab key is being pressed.</p>
  
  <p>I have tried replace html input control with asp.net textbox control but problem remains.</p>
  
  <p>Request: Please prefer a simple solution, that is one that do not require manually setting tabindex in code-behind because that is not very scalable.</p>
  
  <p><code></p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GridExpense.ascx.cs" Inherits="StationaryManagementSystem.GridExpense" %&gt;
  
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;
  
  &lt;script type="text/javascript"&gt;
      function MinQuantity_Blurred() 
      {
          $('#' + '&lt;%= hitMaxQuantitySearch.ClientID %&gt;')[0].value = $('#' + '&lt;%= hitMinQuantitySearch.ClientID %&gt;')[0].value;
      }
  
      function FromDated_Blurred()
      {
          $('#' + '&lt;%= txtToDatedSearch.ClientID %&gt;')[0].value = $('#' + '&lt;%= txtFromDatedSearch.ClientID %&gt;')[0].value;
      }
  &lt;/script&gt;
  
  &lt;asp:Panel ID="panel" runat="server"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;table width="800px"&gt;
                      &lt;tr align="right"&gt;
                          &lt;td class="columnOne"&gt;
                              Item : 
                          &lt;/td&gt;
                          &lt;td class="columnTwo"&gt;
                              &lt;asp:DropDownList ID="ddlItemSearch" runat="server" EnableViewState="true" DataValueField="Id" DataTextField="Name" TabIndex="1005" Width="200px" /&gt;
                          &lt;/td&gt;
  
                          &lt;td class="columnOne"&gt;
                              Officer : 
                          &lt;/td&gt;
                          &lt;td class="columnTwo"&gt;
                              &lt;asp:DropDownList ID="ddlOfficerSearch" runat="server" EnableViewState="true" DataValueField="Id" DataTextField="Name" TabIndex="1010" Width="200px" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;tr align="right"&gt;
                          &lt;td align="right" style="width:200px"&gt;
                              From Quantity: 
                          &lt;/td&gt;
                          &lt;td align="left"&gt;
                              &lt;input type="text" id="hitMinQuantitySearch" name="hitMinQuantitySearch" runat="server" maxlength="9" tabindex="1015"
                                  style="width: 90px; text-align: right" onkeydown="return isNumericKeyDown(event, false);" onkeypress="return isNumericKeyPress(event, false);" 
                                  onblur="MinQuantity_Blurred();" /&gt;
                          &lt;/td&gt;
                          &lt;td align="right" style="width:200px"&gt;
                              To Quantity: 
                          &lt;/td&gt;
                          &lt;td align="left"&gt;
                              &lt;input type="text" id="hitMaxQuantitySearch" name="hitMaxQuantitySearch" runat="server" maxlength="9" tabindex="1020" 
                                  style="width: 90px; text-align: right" onkeydown="return isNumericKeyDown(event, false);" onkeypress="return isNumericKeyPress(event, false);" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
  
                      &lt;tr align="right"&gt;
                          &lt;td class="columnOne"&gt;
                              From Dated :
                          &lt;/td&gt;
  
                          &lt;td class="columnTwo"&gt;
                              &lt;asp:TextBox ID="txtFromDatedSearch" runat="server" MaxLength="11" TabIndex="1025" onblur="FromDated_Blurred();" Width="90px" /&gt;
                              &lt;asp:CalendarExtender ID="ceFromDatedSearch" runat="server" TargetControlID="txtFromDatedSearch" Format="dd-MMM-yyyy" /&gt;
                          &lt;/td&gt;
  
                          &lt;td class="columnOne"&gt;
                              To Dated :
                          &lt;/td&gt;
  
                          &lt;td class="columnTwo"&gt;
                              &lt;asp:TextBox ID="txtToDatedSearch" runat="server" MaxLength="11" TabIndex="1030" Width="90px" /&gt;
                              &lt;asp:CalendarExtender ID="ceToDatedSearch" runat="server" TargetControlID="txtToDatedSearch" Format="dd-MMM-yyyy" /&gt;
                          &lt;/td&gt;
  
                          &lt;td align="left"&gt;
                              &lt;asp:Button ID="btnLoad" runat="server" Text="Load" TabIndex="1035" CssClass="foreRed gradientGreen cornerRound" OnClick="btnLoad_Click" /&gt;
                          &lt;/td&gt;
                      &lt;/&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" DataSourceID="ods" AllowSorting="True" AllowPaging="True" PageSize="5" 
                      AutoGenerateSelectButton="True" onrowcommand="gv_RowCommand" CssClass="gridSapphire" PagerStyle-CssClass="pagerSapphire" 
                      AlternatingRowStyle-CssClass="alterSapphire" onpageindexchanged="gv_PageIndexChanged" Width="100%" EmptyDataText="List is empty." 
                      DataKeyNames="Id" EnableViewState="true" onrowdeleted="gv_RowDeleted"&gt;
                      &lt;PagerSettings Mode="Numeric"/&gt;
                      &lt;Columns&gt;
                          &lt;asp:TemplateField Visible="false"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblIdGrid" runat="server" Text='&lt;%#Eval("Id") %&gt;'/&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField Visible="false"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblIdItemGrid" runat="server" Text='&lt;%#Eval("IdItem") %&gt;' Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField HeaderText="Item" SortExpression="NameItem" ControlStyle-Width="260px"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblNameItemGrid" runat="server" Text='&lt;%#Eval("NameItem") %&gt;' Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField Visible="false"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblIdOfficerGrid" runat="server" Text='&lt;%#Eval("IdOfficer") %&gt;' Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField HeaderText="Officer" SortExpression="NameOfficer" ControlStyle-Width="200px"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblNameOfficerGrid" runat="server" Text='&lt;%#Eval("NameOfficer") %&gt;' Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField HeaderText="Quantity" SortExpression="Quantity" ControlStyle-Width="100px"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblQuantityGrid" runat="server" Text='&lt;%#Eval("Quantity") %&gt;' Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField HeaderText="Dated" SortExpression="Dated" ControlStyle-Width="100px"&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:Label ID="lblDatedGrid" runat="server" Text='&lt;%# DateTime.Parse(Eval("Dated").ToString()).ToString("dd-MMM-yyyy") %&gt;' 
                                      Style="text-align:left; padding-left:5px" /&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
  
                          &lt;asp:TemplateField&gt;
                              &lt;ItemTemplate&gt;
                                  &lt;asp:LinkButton ID="lbDeleteGrid" runat="server" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this Expense?')"&gt;
                                      Delete
                                  &lt;/asp:LinkButton&gt;
                              &lt;/ItemTemplate&gt;
                          &lt;/asp:TemplateField&gt;
                      &lt;/Columns&gt;
                      &lt;PagerStyle CssClass="pagerSapphire" /&gt;
                      &lt;AlternatingRowStyle CssClass="alterSapphire" /&gt;
                  &lt;/asp:GridView&gt;
                  &lt;asp:ObjectDataSource ID="ods" runat="server" TypeName="StationaryManagementSystem.Classes.DAL.Expense"
                      SelectMethod="Search" SelectCountMethod="CountSearch" SortParameterName="sSortExpression" EnablePaging="true"            
                      StartRowIndexParameterName="iZeroIndexStartPage" MaximumRowsParameterName="iSizePage" 
                      onselecting="ods_Selecting" 
                      DeleteMethod="Delete" ondeleting="ods_Deleting"&gt;
                          &lt;DeleteParameters&gt;
                              &lt;asp:Parameter Name="ID" Type="Int64" /&gt;
                          &lt;/DeleteParameters&gt;
                  &lt;/asp:ObjectDataSource&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  &lt;/asp:Panel&gt;
  </code></pre>
  
  <p></code></p>