gpt4 book ai didi

c# - GridView - 将焦点设置到特定单元格

转载 作者:太空宇宙 更新时间:2023-11-03 10:49:57 24 4
gpt4 key购买 nike

我看过很多关于这个问题的帖子,但是,他们都建议我们使用如下方法:dgv.CurrentCelldgv.Rows[row].Cells[cellno ].已选择。 Intellisense 找不到这样的方法。

我在 gridview 中有一个文本框,我在其中使用了 OnTextChanged 方法。然后,在我的 C# 代码中,我更新了这个数量,然后网格自动刷新,并返回到顶行,即使我们已经向下滚动了几页。我还尝试在我的 .aspx 页面的“页面”部分中放入 MaintainScrollPositionOnPostback="true",但似乎没有任何效果。我们使用的是 .Net Framework 4.0。

<asp:GridView ID="gvOrderDetails" runat="server" AlternatingRowStyle-BackColor="#FAFAFA" Width="940px" AutoGenerateColumns="False" AllowSorting="True" OnSorting="SortOrderDetails"
OnRowCommand="gvOrderDetails_RowCommand" EmptyDataText="No Data to Display"
DataKeyNames="STOREORDNUM" HeaderStyle-Height="22px"
onselectedindexchanged="gvOrderDetails_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" /><EditRowStyle BackColor="#2461BF"/>
<FooterStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" />
<HeaderStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" BorderWidth="1px" BorderColor="Gray"/><PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" Height="22px"/>
<Columns>
<asp:BoundField DataField="ITMCD" HeaderText="Item Code" SortExpression="ItemCode" >
</asp:BoundField>
....
<asp:TemplateField HeaderText="Order Qty" SortExpression="OrderQty" >
<ItemTemplate>
<asp:TextBox ID="OrderQty" runat="server" Width="36" MaxLength="5" class="numberinput" AutoPostBack="true" OnTextChanged="buttonUpdateQty_Click" Text='<%# Bind("ORDERQTY") %>' ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

在后面的代码中,我尝试了这两件事:

gvOrderDetails.Rows[row.RowIndex].FindControl("OrderQty").Focus();
gvOrderDetails.Rows[row.RowIndex].Cells[7].Controls[0].Focus();

最佳答案

您需要将所需的控制单元格转换为Textbox 控件,然后在其上调用Focus() 方法。

试试这个:

TextBox txtOrderQty = (TextBox) gvOrderDetails.Rows[row.RowIndex].FindControl("OrderQty");
txtOrderQty.Focus();

关于c# - GridView - 将焦点设置到特定单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21791339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com