0

我正在尝试获取文本框 OntextChanged 的​​行和列位置。

如果我这样做,我可以获得列位置:

TextBox txtScore = sender;
ListViewItem item = (ListViewItem)txtScore.NamingContainer;
int col = ((ListView)item.NamingContainer).DataKeys(item.DataItemIndex).Values(0);

在我将下面的代码段转换为用户控件之前,它一直有效。

代码片段

 <asp:ListView ID="techs" runat="server" ItemPlaceholderID="lvItemPlaceholder" DataKeyNames="Number"
        OnItemDataBound="techs_ItemDataBound">
        <LayoutTemplate>
            <asp:PlaceHolder runat="server" ID="lvItemPlaceholder" />
        </LayoutTemplate>
        <ItemTemplate>
            <tr>
                <td>
                    Tech
                    <%# Eval("Number")%>
                </td>
                <td>
                    <asp:TextBox ID="tech" runat="server" Text='<%# Eval("Name") %>' />
                </td>
                <asp:ListView ID="scorePatterns" runat="server" ItemPlaceholderID="lvScorePatternsItemPlaceholder"
                    OnItemDataBound="scorePatterns_ItemDataBound" DataKeyNames="Ref">
                    <LayoutTemplate>
                        <asp:PlaceHolder runat="server" ID="lvScorePatternsItemPlaceholder" />
                    </LayoutTemplate>
                    <ItemTemplate>
                        <td>
                            <table>
                                <asp:ListView ID="scores" runat="server" ItemPlaceholderID="lvScoresItemPlaceholder"
                                    OnItemDataBound="scores_ItemDataBound" DataKeyNames="Ref,Instance">
                                    <LayoutTemplate>
                                        <asp:PlaceHolder runat="server" ID="lvScoresItemPlaceholder" />
                                    </LayoutTemplate>
                                    <ItemTemplate>
                                        <tr>
                                            <td>
                                                <asp:TextBox runat="server" ID="txtScore" Width="50" AutoPostBack="true" OnTextChanged="txtScore_TextChanged" />
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                </asp:ListView>
                            </table>
                        </td>
                    </ItemTemplate>
                </asp:ListView>
                <td>
                    <asp:Label runat="server" ID="lblDate" Text='<%# Eval("Date") %>' />
                </td>
            </tr>
    </ItemTemplate>

4

0 回答 0