This is my View
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InsertUser.aspx.cs" Inherits="WebApplication1.InsertUser" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"></asp:ObjectDataSource>
<asp:TextBox></asp:TextBox> // i want to bind the Fullname Property here
<asp:Button></asp:Button> // i want to bind the Save() here
</div>
</form>
</body>
</html>
and i want to bind the property and method from my viewmodel. Is it possible?
this is my ViewModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services;
namespace Testing.ViewModel
{
public class UserVM
{
public int UserID { get; set; }
public string Fullname { get; set; }
[WebMethod]
public void Save()
{
}
}
}
can someone guide me to the right direction? i manage to bind the Grid with ObjectDataSource and i can perform CRUD operations but i cant manage to bind a View to a ViewModel.
this is my sample Binding from ViewModel with CRUD operation to my View with Grid
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title></title></head><body><form id="form1" runat="server">
<div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="Testing.Model.User" DeleteMethod="DeleteUser" InsertMethod="CreateUser" SelectMethod="GetUsers" TypeName="Testing.ViewModel.UserListVM" UpdateMethod="UpdateUser"></asp:ObjectDataSource>
<asp:GridView ID="GridView1" DataSourceID="ObjectDataSource1" runat="server" AllowPaging="True" AutoGenerateColumns="False">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID" />
<asp:BoundField DataField="Fullname" HeaderText="Fullname" SortExpression="Fullname" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
UserListVM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Testing.Model;
namespace Testing.ViewModel
{
public class UserListVM
{
public UserListVM()
{
}
public IEnumerable<User> GetUsers()
{
return VMIndex.Users;
}
public User UpdateUser(User user)
{
throw new NotImplementedException();
}
public User DeleteUser(User user)
{
throw new NotImplementedException();
}
public User CreateUser(User user)
{
throw new NotImplementedException();
}
}
}
Any help please.. Thanks in advance.