从 ASP.NET 中的 Gridview 获取当前行
我有一个带有删除和编辑按钮的 Gridview ,看起来
<asp:GridView ID="grdTrackedItems" runat="server" AutoGenerateColumns="False" Width="330px"
BorderStyle="None" OnRowDataBound="OnRowDataBoundTrackedItems" OnRowDeleting="OnRowDeletingTrackedItems">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblItem" runat="server" Text='<%# Eval("Item") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Resources/Images/Delete.png"
Height="12" Width="12" ToolTip="Delete" CommandName="Delete" />
</ItemTemplate>
<ItemStyle Width="22px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Resources/Images/Edit.png"
Height="12" Width="12" ToolTip="Edit" />
</ItemTemplate>
<ItemStyle Width="22px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
页面底部有一个文本框和“保存”按钮。当我单击 gridview 中的编辑按钮时,我想在文本框中显示项目名称。我该怎么做?
I have a Gridview with delete and edit buttons looks like
<asp:GridView ID="grdTrackedItems" runat="server" AutoGenerateColumns="False" Width="330px"
BorderStyle="None" OnRowDataBound="OnRowDataBoundTrackedItems" OnRowDeleting="OnRowDeletingTrackedItems">
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="lblItem" runat="server" Text='<%# Eval("Item") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Resources/Images/Delete.png"
Height="12" Width="12" ToolTip="Delete" CommandName="Delete" />
</ItemTemplate>
<ItemStyle Width="22px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Resources/Images/Edit.png"
Height="12" Width="12" ToolTip="Edit" />
</ItemTemplate>
<ItemStyle Width="22px" />
</asp:TemplateField>
</Columns>
</asp:GridView>
I have a text box and Save button on bottom of the page. I want to display the item name in the textbox when I click on the edit button from gridview. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为 RowEditing 事件提供一个处理程序,然后在该处理程序中更新文本框。
Provide a handler for the RowEditing event, and then update your textbox in that handler.
在编辑按钮单击处理程序内,您可以访问当前行,如下所示:
inside the edit button click handler you can access the current row as below:
我从 river-blue 得到了解决方案回答。
将 DataKeyNames="Item" 添加到 Gridview
并在编辑按钮内单击处理程序
I got the solution from river-blue's answer.
Add DataKeyNames="Item" to Gridview
and inside the edit button click handler