0

セットアップ

SharePoint 2010にデプロイしようとしているアプリケーションページがあります。このページには、次のようなSPGridViewとLinqDataSourceが含まれています。

<asp:UpdatePanel ID="Update" runat="server" >
    <ContentTemplate>
        <center>
            <asp:LinqDataSource runat="server"                    
                    ID="EntitiesSource" 
                    onSelecting="EntitiesSource_Selecting"                                
                    EnableDelete="true"
                    EnableUpdate="true"
                    EnableInsert="true" />

            <SharePoint:SPGridView runat="server"
                    ID="EntitiesGrid"
                    AutoGenerateColumns="false"
                    DataKeyNames="Key"
                    FilteredDataSourcePropertyName="Where"
                    FilteredDataSourcePropertyFormat='{1} == "{0}"'
                    OnRowDeleting="EntitiesGrid_RowDeleting"
                    OnRowUpdating="EntitiesGrid_RowUpdating"
                    AllowPaging="true"
                    AllowSorting="true"
                    PageSize="20"
                    ShowFooter="true"
                    DataSourceID="EntitiesSource">

                <pagersettings mode="Numeric"
                       position="Bottom"           
                       pagebuttoncount="20"/>

                <pagerstyle backcolor="Control"
                       verticalalign="Bottom"
                       horizontalalign="Center"/>

                <Columns>                            

                    <asp:CommandField HeaderText="Actions" ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ShowCancelButton="true"  />
                    <asp:BoundField HeaderText="Key" DataField="Key" SortExpression="Key" />
                    <asp:BoundField HeaderText="Var a" DataField="A" SortExpression="A" />
                    <asp:BoundField HeaderText="Var b" DataField="B" SortExpression="B" />
                    <asp:BoundField HeaderText="Var c" DataField="C" SortExpression="C" />

                </Columns>                                    

            </SharePoint:SPGridView>  
        </center>

    </ContentTemplate>
</asp:UpdatePanel>

背後にあるコードは次のようになります。

public partial class EntitiesPage: LayoutsPageBase
{
    private MyContext _dbcontext;
    private MyContext DBContext
    {
        get
        {
            if (_dbcontext == null)
            {
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["entitiesConnectionString"].ConnectionString;
                _dbcontext = new MyContext(connectionString);
            }

            return _dbcontext;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        EntitiesGrid.PagerTemplate = null;
    }

    protected void EntitiesGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {         
        string key = (string)e.Keys[0];
        DBContext.RemoveEntity(key);
        DBContext.SubmitChanges();

        //the entity is gone from the context now             
        EntitiesGrid.DataBind();                      
    }

    protected void EntitiesGrid_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string key = (string)e.Keys["Key"];
        string newKey = (string)e.NewValues["Key"];

        if (string.Equals(key, newKey))
        {
            Entity entity = DBContext.GetEntity(key);
            entity.A = (string)e.NewValues["A"];
            entity.B = (string)e.NewValues["B"];
            entity.C = (string)e.NewValues["C"];
            DBContext.SubmitChanges();
        }
        else
        {
            //We need to remove the old one and make a new one since we can't edit the key
            DBContext.RemoveEntity(key);
            DBContext.AddEntity(new Entity{ Key = newKey, A = (string)e.NewValues["A"], B = (string)e.NewValues["B"], C = (string)e.NewValues["C"] });
            DBContext.SubmitChanges();
        }
    }

    protected void EntitiesSource_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        e.Result = DBContext.Entities;
    }

'MyContext'クラスは、DataContextを継承し、linq2sqlを使用するカスタムクラスです。それは私自身のエンティティクラスの単一のテーブルを持っています。

問題

データベースからのデータの読み取り、並べ替え、およびページングは​​、非常にうまく、非常に迅速に機能します。ページをリロードしなくてもグリッドが変更されます。ただし、行を更新または削除する場合、データベースに加えられた変更を確認する前に、手動で更新する必要があります。私が行った変更は、DataContextとデータベースに対してすぐに実行されると確信しています。ここにないリンクは、DataSourceまたはGridView(あるいはその両方)を更新しているようです。

これをデバッグするのは面倒で、問題がDataSource / GridViewのオブジェクトを更新しているのか、それともそれらのオブジェクトの後にユーザーにコールバックを送信しているのかを実際に判断することはできません(または判断方法がわかりません)。更新されました。

4

1 に答える 1

0

データソースをグリッドにバインドし、変更後にそのメソッドを呼び出すメソッドを作成しようとしましたか?

// Create a method for binding the data
public void bindTheGrid()
{
     EntitiesGrid.Datasource = variables; //This is whatever your properties are etc
     EntitiesGrid.DataBind();
}

//Call the method after you succesffuly make changes to the database etc
bindTheGrid();
于 2012-10-10T13:47:51.710 に答える