【发布时间】:2014-01-29 13:01:15
【问题描述】:
如果之前有人问过这个问题,我深表歉意,但我正在开发一个带有Gridview 的用户控件。
(我这样做的原因是我想在我的应用程序的不同页面上重复使用控件)。
我想在这个Gridview 上使用modelbinding,但是当我尝试启用它时,它不起作用。
当我尝试编译时,它给了我以下错误:
'IsValid' is not a member of 'System.Web.ModelBinding.ModelState'.
'AddModelError' is not a member of 'System.Web.ModelBinding.ModelState'.
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="test.ascx.vb" Inherits="Octoplus.test" %>
<asp:GridView ID="GridView1" runat="server" ItemType="Octoplus.OrderHeader" UpdateMethod="GridView1_UpdateItem">
Imports System.Web.ModelBinding
Inherits System.Web.UI.UserControl
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
' The id parameter name should match the DataKeyNames value set on the control
Public Sub GridView1_UpdateItem(ByVal id As Integer)
Dim item As Octoplus.OrderHeader = Nothing
' Load the item here, e.g. item = MyDataLayer.Find(id)
If item Is Nothing Then
' The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", id))
Return
End If
TryUpdateModel(item)
If ModelState.IsValid Then
' Save changes here, e.g. MyDataLayer.SaveChanges()
End If
End Sub
有人有想法吗?
提前致谢。
【问题讨论】:
标签: c# asp.net .net gridview model-binding