[英]ASP.NET C# GridView Tab Index issue
似乎在向ASP.NET GridView添加行时,Tab索引的行为不符合预期(或期望)。 选项卡将向下移动到列中的每一行,然后移动到下一列,依此类推,而不是在一行中的每列上进行制表,然后移动到下一行。 简单地说,它将垂直而不是水平。 对于用户严重依赖键盘输入的数据输入应用程序,这可能是一个问题。
针对这个问题的解决方案?
我已经搞砸了一段时间并且有这个解决方案! 希望它可以帮助其他有同样问题的人。
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
对于每个控件,您可以将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>
然后在代码后面增加一个TabIndex计数器:
private int _tabIndex = 0;
public int TabIndex
{
get
{
_tabIndex++;
return _tabIndex;
}
}
您可以在rowdatabound事件上手动为网格内的所有控件指定TabIndex。 计算出您希望在特定行上选择多少个控件,然后根据行索引生成Tab键顺序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.