Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET C#GridView选项卡索引问题_C#_Asp.net_Gridview - Fatal编程技术网

ASP.NET C#GridView选项卡索引问题

ASP.NET C#GridView选项卡索引问题,c#,asp.net,gridview,C#,Asp.net,Gridview,似乎在向ASP.NET GridView添加行时,选项卡索引的行为不符合预期(或期望)。该选项卡将向下移动列中的每一行,然后移动到下一列,以此类推,而不是在一行中的每一列上使用选项卡,然后移动到下一列。简单地说,它将垂直调整而不是水平调整。对于用户严重依赖键盘输入的数据输入应用程序来说,这可能是一个问题 有没有解决此问题的方法?您可以在rowdatabound事件中手动为网格中的所有控件分配TabIndex。计算出要在特定行上制表的控件数量,然后根据行索引制定制表顺序。我已经使用了一段时间,并且

似乎在向ASP.NET GridView添加行时,选项卡索引的行为不符合预期(或期望)。该选项卡将向下移动列中的每一行,然后移动到下一列,以此类推,而不是在一行中的每一列上使用选项卡,然后移动到下一列。简单地说,它将垂直调整而不是水平调整。对于用户严重依赖键盘输入的数据输入应用程序来说,这可能是一个问题


有没有解决此问题的方法?

您可以在rowdatabound事件中手动为网格中的所有控件分配TabIndex。计算出要在特定行上制表的控件数量,然后根据行索引制定制表顺序。

我已经使用了一段时间,并且有了这个解决方案!希望它能帮助其他有同样问题的人

protected void theGridView_DataBound(object sender, EventArgs e)
{
    SetTabIndexes();
}


private void SetTabIndexes()
{
    short currentTabIndex = 0;
    inputFieldBeforeGridView.TabIndex = ++currentTabIndex;

    foreach (GridViewRow gvr in theGridView.Rows)
    {
        DropDownList dropDown1 = (DropDownList)gvr.FindControl("dropDown1");
        dropDown1.TabIndex = ++currentTabIndex;

        TextBox inputField1 = (TextBox)gvr.FindControl("inputField1");
        inputField1.TabIndex = ++currentTabIndex;

        TextBox inputField2 = (TextBox)gvr.FindControl("inputField2");
        inputField2.TabIndex = ++currentTabIndex; 

        TextBox inputField3 = (TextBox)gvr.FindControl("inputField3");
        inputField3.TabIndex = ++currentTabIndex;
    }

    someLinkAfterGridView.TabIndex = ++currentTabIndex;
}
看看

对于每个控件,可以将TabIndex设置为代码隐藏中的属性

<asp:GridView ID="gv" runat="server">
  <columns>
    <asp:TemplateField HeaderText="Action" ShowHeader="False" Visible="true"> 
      <ItemTemplate>
        <asp:CheckBox ID="cbGroup" Checked="true" runat="server" TabIndex='<%# TabIndex %>' Text='<%# Eval("Title") %>' />
      </ItemTemplate>
    </asp:TemplateField>
  </columns>
</asp:GridVeiw>

确切地对于其他可能正在谷歌上搜索这个问题的人来说,这更像是一个问题。我在那里什么也找不到。就是这样+1个干净优雅的解决方案,感谢包括并给予原作者信任。
private int _tabIndex = 0;

public int TabIndex
{
  get
  {
    _tabIndex++;
    return _tabIndex;
  }
}