如何进入FormView的编辑模式?
我有 FormView:
<asp:FormView ID="fvReport" runat="server" DefaultMode="ReadOnly" AllowPaging="false" OnModeChanging="fvReport_ModeChanging" DataKeyNames="id">
protected void fvReport_ModeChanging(Object sender, FormViewModeEventArgs e)
{
switch (e.NewMode)
{
case FormViewMode.Edit:
fvReport.AllowPaging = false;
break;
}
}
在 ItemTamplate 中我放置了 LinkButton:
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit" CommandArgument='<%# Eval("id") %>'>Редактировать</asp:LinkButton>
当然,FormView 有 EditItemTemplate 部分。
当我单击按钮时,FormView 会刷新并保持只读状态。我做错了什么?
I have FormView:
<asp:FormView ID="fvReport" runat="server" DefaultMode="ReadOnly" AllowPaging="false" OnModeChanging="fvReport_ModeChanging" DataKeyNames="id">
protected void fvReport_ModeChanging(Object sender, FormViewModeEventArgs e)
{
switch (e.NewMode)
{
case FormViewMode.Edit:
fvReport.AllowPaging = false;
break;
}
}
in ItemTamplate I put LinkButton:
<asp:LinkButton ID="lbEdit" runat="server" CausesValidation="true" CommandName="Edit" CommandArgument='<%# Eval("id") %>'>Редактировать</asp:LinkButton>
Of course, FormView has EditItemTemplate section.
When I click Button, FormView is refreshed and stays in ReadOnly. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须调用 FormView 的 ChangeMode 方法并传递模式
you have to call ChangeMode method of FormView and pass the mode
我通常用来从 formView 进入编辑模式的另一个选项是添加和定义 EditItemTemplate 元素。这使得您的应用程序可编辑变得更加容易。
在 formView 中,您可能需要将
DefaultMode
更改为 Edit。也在你的代码后面尝试:Another option which I commonly use to go into edit mode from a formView is to add and define the EditItemTemplate element. This makes it a lot easier to make your application editable.
Within your formView you may need to change your
DefaultMode
to Edit. Also in your code behind try:您的
FormView
未切换可能还有其他原因。这通常是由于 HTML 格式错误造成的。您的设计器有时会通过显示类似以下内容来告诉您格式错误的部分...在某些情况下,当您没有收到此明显消息时,
FormView
未切换通常是到一些不太明显的事情,比如同样糟糕的AssociatedControlId
属性。我建议您查看标签、验证器以及任何控件必须与另一个控件关联的内容。像这样小的东西...注意到上面故意使用了
textAccessGranted
,而不是实际的textAccessGrantedBy
TextBox
吗?这就是我过去的命令处理失败的地方。There could be other reasons why your
FormView
isn't switching over. It's usually down to badly formatted HTML. Your designer sometimes tells you of malformed sections by displaying something like this...On those occasions when you don't get this obvious message,
FormView
not switching over is usually down to something a little less obvious, such as badAssociatedControlId
attributes. I would recommend looking at you labels, validators and anything where a control has to be associated to another. Something as small as this...Notice the deliberate use of
textAccessGranted
above, rather than the actualtextAccessGrantedBy
TextBox
? That's where the command handling has failed for me in the past.