Spread for ASP.NET 10 Product Documentation
DeleteMethod Property (SheetView)
Example 


Gets or sets the name of the method to call in order to delete data.
Syntax
'Declaration
 
Public Property DeleteMethod As String
'Usage
 
Dim instance As SheetView
Dim value As String
 
instance.DeleteMethod = value
 
value = instance.DeleteMethod
public string DeleteMethod {get; set;}
Example
This code is part of a larger example installed by the setup.
<FarPoint:SheetView SheetName="Sheet1" SelectMethod="GetUsers" DeleteMethod="DeleteUser"
                    InsertMethod="InsertUser" UpdateMethod="UpdateUser" AllowDelete="true" AllowInsert="true">
                </FarPoint:SheetView>

public partial class FR1917 : System.Web.UI.Page
{
    SampleDataModel db = new SampleDataModel("ConnectionString");
    public System.Data.Entity.DbSet<User> GetUsers() { return db.Users; }

  public void UpdateUser(string userName, string fullName, string description, string phone)
  {
      if (!this.Page.ModelState.IsValid) return;

      FpSpread1.Sheets[2].Cells[0, 0].Text += userName;
      FpSpread1.Sheets[2].Cells[0, 1].Text += fullName;
      FpSpread1.Sheets[2].Cells[0, 2].Text += description;

      User found = db.Users.FirstOrDefault(u => u.UserName == userName);
      if (found != null)
      {
          found.FullName = fullName;
          found.Description = description;
          found.Phone = phone;
      }
      db.SaveChanges();
  }

  public void InsertUser(string userName, string fullName, string description)//We can even ignore Phone parameter
  {
      if (!this.Page.ModelState.IsValid) return;
      User found = db.Users.FirstOrDefault(u => u.UserName == userName);
      if (found != null)
          throw new Exception("This user name has already been used. Please choose another name.");
      User user = new User
      {
          UserName = userName,
          FullName = fullName,
          Description = description
      };
      db.Users.Add(user);
      db.SaveChanges();
  }

  public void DeleteUser(string userName)//Other properties are not important
  {
      User found = db.Users.FirstOrDefault(u => u.UserName == userName);
      if (found != null) db.Users.Remove(found);
      db.SaveChanges();
  }

  protected void Page_Load(object sender, EventArgs e)
  {
    if (IsPostBack) return;
    FpSpread1.ActiveSheetView.PageSize = 100;
    FpSpread1.ActiveSheetView.EnableRowEditTemplate = true; 
    if (FpSpread1.ActiveSheetView.ColumnCount > 2)
    {
      FpSpread1.ActiveSheetView.Columns[1].Width = 150;
      FpSpread1.ActiveSheetView.Columns[2].Width = 200;
    }
  }

  protected void Button1_Click(object sender, EventArgs e)
  {
    FpSpread1.Sheets[0].Reset();
  }
}
<FarPoint:SheetView SheetName="Sheet1" SelectMethod="GetUsers" DeleteMethod="DeleteUser"
                    InsertMethod="InsertUser" UpdateMethod="UpdateUser" AllowDelete="true" AllowInsert="true">
                </FarPoint:SheetView>

Public Partial Class FR1917
    Inherits System.Web.UI.Page
    Private db As New SampleDataModel("ConnectionString")
    Public Function GetUsers() As System.Data.Entity.DbSet(Of User)
        Return db.Users
    End Function

    Public Sub UpdateUser(userName As String, fullName As String, description As String, phone As String)
        If Not Me.Page.ModelState.IsValid Then
            Return
        End If

        FpSpread1.Sheets(2).Cells(0, 0).Text += userName
        FpSpread1.Sheets(2).Cells(0, 1).Text += fullName
        FpSpread1.Sheets(2).Cells(0, 2).Text += description

        Dim found As User = db.Users.FirstOrDefault(Function(u) u.UserName = userName)
        If found IsNot Nothing Then
            found.FullName = fullName
            found.Description = description
            found.Phone = phone
        End If
        db.SaveChanges()
    End Sub

    Public Sub InsertUser(userName As String, fullName As String, description As String)
    'We can even ignore Phone parameter
        If Not Me.Page.ModelState.IsValid Then
            Return
        End If
        Dim found As User = db.Users.FirstOrDefault(Function(u) u.UserName = userName)
        If found IsNot Nothing Then
            Throw New Exception("This user name has already been used. Please choose another name.")
        End If
        Dim user As New User() With { _
            .UserName = userName, _
            .FullName = fullName, _
            .Description = description _
        }
        db.Users.Add(user)
        db.SaveChanges()
    End Sub

    Public Sub DeleteUser(userName As String)
    'Other properties are not important
        Dim found As User = db.Users.FirstOrDefault(Function(u) u.UserName = userName)
        If found IsNot Nothing Then
            db.Users.Remove(found)
        End If
        db.SaveChanges()
    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs)
        If IsPostBack Then
            Return
        End If
        FpSpread1.ActiveSheetView.PageSize = 100
        FpSpread1.ActiveSheetView.EnableRowEditTemplate = True
        If FpSpread1.ActiveSheetView.ColumnCount > 2 Then
            FpSpread1.ActiveSheetView.Columns(1).Width = 150
            FpSpread1.ActiveSheetView.Columns(2).Width = 200
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs)
        FpSpread1.Sheets(0).Reset()
    End Sub
End Class
Requirements

Target Platforms: Windows 7, Windows 8, Windows 10, Windows Vista, Windows Server 2003, Windows Server 2008, Windows Server 2012, Windows XP Professional

See Also

Reference

SheetView Class
SheetView Members

 

 


Copyright © GrapeCity, inc. All rights reserved.