PowerTools SPREAD for ASP.NET 8.0J
DeleteMethod プロパティ (SheetView)

データを削除するために呼び出すメソッドの名前を取得または設定します。
構文
'Declaration
 
Public Property DeleteMethod As String
public string DeleteMethod {get; set;}
このコードは、セットアップによってインストールされるコード例の一部です。
<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();
    }

    // We can even ignore Phone parameter
    public void InsertUser(string userName, string fullName, string description)
    {
        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
参照

SheetView クラス
SheetView メンバ

 

 


© 2003-2015, GrapeCity inc. All rights reserved.