开发者

Is InsertMethod broken when using ASPxGridView and ObjectDatasource with a custom EditForm?

I have an ASPxGridView, currently 11.1.7.0, which I populate with an ObjectDatasource. Everything works as expected until I use a custom editform. In another control i solved this by using the OnRowInserting attribute in the aspxgridview control, but I dont like this since it's extra work compared to using the objectdatasource.

The code looks something like this.

<dx:ASPxGridView ID="ASPxGridView1" runat="server" 
    ClientIDMode="AutoID" 
    AutoGenerateColumns="False"
    KeyFieldName="UserId" 
    DataSourceID="ObjectDataSource1"
    ClientInstanceName="grid" 
    onhtmleditformcreated="AsPxGridView1HtmlEditFormCreated">

    <SettingsEditing PopupEditFormWidth="600" PopupEditFormModal="true" Mode="EditForm" />

    <Templates>
        <TitlePanel>
            <dx:ASPxButton ID="New" runat="server" Text="Ny användare" ClientInstanceName="New" AutoPostBack="false">
                <ClientSideEvents Click="function (s, e) { grid.AddNewRow(); }" />
            </dx:ASPxButton>
        </TitlePanel>

        <EditForm>
            First Name: <dx:ASPxTextBox ID="FirstName" runat="server" />
            <dx:ASPxGridViewTemplateReplacement ID="UpdateButton" ReplacementType="EditFormUpdateButton" runat="server" />
            <dx:ASPxGridViewTemplateReplacement ID="CancelButton" ReplacementType="EditFormCancelButton" runat="server" />
        </EditForm>
    </Templates>

    <Columns>
        <dx:GridViewDataTextColumn FieldName="UserId" VisibleIndex="0" />
        <dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="2" />
        <dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="3" />
    </Columns>
</dx:ASPxGridView>

<asp:ObjectDataSource 
    ID="ObjectDataSource1" 
    TypeName="UserData" 
    SelectMethod="GetItems"
    UpdateMethod="ItemUpdate" 
    InsertMethod="ItemInsert" 
    DeleteMethod="ItemDelete"
    runat="server">
        <InsertParameters>
            <asp:Parameter Name="FirstName" Type="String"/>
        </InsertParameters>
</asp:ObjectDataSource>

And t开发者_运维知识库he UserData object

public class UserData
{
    public List<TblProUserData> GetItems()
    {
        var tblProUserData = new TblProUserData();
        tblProUserData.Fill();

        return tblProUserData.List;
    }

    public void ItemDelete(int userId)
    { }

    public void ItemUpdate()
    { }

    public void ItemInsert(string FirstName)
    {
        // This method gets called, but the FirstName is null.
    }
}

The problem is that the ItemInsert gets called, but the FirstName attribute is always null.

Is this a bug? is there a way around this? Did I miss something?

Thanks.


It is necessary to use the Two-Way data-binding technique to bind template editors with DataItem's fields:

<dx:ASPxTextBox ID="FirstName" runat="server" Text='<%#Bind("FirstName")%>' />


Based off the following question, specifying TypeName="UserData" could be causing the problem.

ObjectDataSource not calling Insert method when it has extra parameters

Try removing that from the asp:ObjectDataSource and see if the ItemInsert method works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜