本文介绍了从ASP.NET中的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>
我在页面底部有一个文本框和保存"按钮.当我从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?
推荐答案
为RowEditing事件提供处理程序,然后在该处理程序中更新文本框.
Provide a handler for the RowEditing event, and then update your textbox in that handler.
<asp:GridView ID="grdTrackedItems" runat="server"
AutoGenerateColumns="False" Width="330px"
...
OnRowEditing="EditRecord">
<Columns>
protected void EditRecord(object sender, GridViewEditEventArgs e)
{
Label lbl = (Label)grdTrackedItems.Rows[e.NewEditIndex].Cells[0].FindControl("lblItem");
MyTextBox.Text = lbl.text;
}
这篇关于从ASP.NET中的Gridview获取当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!