【发布时间】:2015-09-25 14:17:56
【问题描述】:
我有一个在模板字段中显示数据的网格视图,它需要通过单击链接按钮来显示有关要显示的记录的更多信息。现在,我让“详细信息”链接按钮通过调用 gridview 上的编辑命令来显示信息,以便它切换到 EditItemTemplate。在 EditItemTemplate 中,我有一个用于取消的链接按钮,然后是一个编辑按钮,单击该按钮时会显示带有更新命令的更新按钮,但我需要它遍历该行并将 EditItemTemplate 中的所有文本框设置为 ReadOnly=false 所以以便在选择更新命令之前对其进行编辑。以下是代码摘要:
<ItemTemplate>
*basic information displayed*
<asp:LinkButton runat="server" CommandName="Edit" Text="Details"></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
*A bunch of readonly textboxes that display the extra information*
<asp:LinkButton runat="server" CommandName="Update" Text="Update" Visible="false"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Edit" OnClick="editButton_Click"></asp:LinkButton>
</EditItemTemplate>
以及使按钮按我想要的方式显示的事件代码,但我不确定如何遍历 EditItemTemplate,或者即使这是我应该做的:
Protected Sub editButton_Click(sender As Object, e As EventArgs)
sender.FindControl("updateButton").Visible = True
sender.FindControl("editbutton").Visible = False
For Each t In ?EditItemTemplate?
Dim textbox = TryCast(t, System.Web.UI.WebControls.TextBox)
If textbox IsNot Nothing Then
textbox.ReadOnly = False
End If
Next
End Sub
所以我的问题是如何让它工作,或者我应该如何设置 GridViewCommands 否则
【问题讨论】:
-
也许利用 GridView 提供的默认机制会更有意义。每个需要可编辑的列都有一个项目模板和一个编辑模板,只需使用“编辑”按钮触发“编辑”命令。这样 GridView 中的相应行将使用编辑模板呈现每一列,这正是您所需要的