2010-07-12 91 views
1

貝婁是我的.aspx aspxGridview語法AspxGridView不支持指定的方法。問題

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
      KeyFieldName="intProductCode" onrowinserted="ASPxGridView1_RowInserted"> 
      <Columns> 
       <dx:GridViewCommandColumn VisibleIndex="0"> 
        <EditButton Visible="True"> 
        </EditButton> 
        <NewButton Visible="True"> 
        </NewButton> 
        <DeleteButton Visible="True"> 
        </DeleteButton> 
       </dx:GridViewCommandColumn> 
       <dx:GridViewDataTextColumn Caption="intProductCode" FieldName="intProductCode" 
        VisibleIndex="1"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="strProductName" FieldName="strProductName" 
        VisibleIndex="2"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="SKU" FieldName="SKU" VisibleIndex="3"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="PACK" FieldName="PACK" VisibleIndex="4"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="intQtyPerCase" FieldName="intQtyPerCase" 
        VisibleIndex="5"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="mnyCasePrice" FieldName="mnyCasePrice" 
        VisibleIndex="6"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="intTBQtyPerCase" 
        FieldName="intTBQtyPerCase" VisibleIndex="7"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataCheckColumn Caption="bIsActive" FieldName="bIsActive" 
        VisibleIndex="8"> 
       </dx:GridViewDataCheckColumn> 
       <dx:GridViewDataTextColumn Caption="intSortingOrder" 
        FieldName="intSortingOrder" VisibleIndex="9"> 
       </dx:GridViewDataTextColumn> 
       <dx:GridViewDataTextColumn Caption="strProductAccCode" 
        FieldName="strProductAccCode" VisibleIndex="10"> 
       </dx:GridViewDataTextColumn> 
      </Columns> 
     </dx:ASPxGridView> 

貝婁是我的C#語法:

protected void Page_Load(object sender, EventArgs e) 
     { 
      if (this.IsPostBack != true) 
      { 
       BindGridView(); 
      } 
     } 

     private void BindGridView() 
     { 
      DB_OrderV2DataContext db = new DB_OrderV2DataContext(); 
      var r = from p in db.tblProductInfos 
        select p; 
      ASPxGridView1.DataSource = r; 
      ASPxGridView1.DataBind(); 
     } 

     protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e) 
     { 
      DB_OrderV2DataContext db = new DB_OrderV2DataContext(); 
      var r= from p in db.tblProductInfos 
        select p; 
      e.QueryableSource = r; 


     } 

     protected void ASPxGridView1_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e) 
     { 
      DB_OrderV2DataContext db = new DB_OrderV2DataContext(); 


      tblProductInfo otblProductInfo = new tblProductInfo(); 

      otblProductInfo.intProductCode = (db.tblProductInfos.Max(p => (int?)p.intProductCode) ?? 0) + 1;//oProductController.GenerateProductCode(); 
      otblProductInfo.strProductName = Convert.ToString(e.NewValues["strProductName"]); 
      otblProductInfo.SKU = Convert.ToString(e.NewValues["SKU"]); 
      otblProductInfo.PACK = Convert.ToString(e.NewValues["PACK"]); 
      otblProductInfo.intQtyPerCase = Convert.ToInt32(e.NewValues["intQtyPerCase"]); 
      otblProductInfo.mnyCasePrice = Convert.ToDecimal(e.NewValues["mnyCasePrice"]); 
      otblProductInfo.intTBQtyPerCase = Convert.ToInt32(e.NewValues["intTBQtyPerCase"]); 
      otblProductInfo.bIsActive = Convert.ToBoolean(e.NewValues["bIsActive"]); 
      otblProductInfo.intSortingOrder = (db.tblProductInfos.Max(p => (int?)p.intSortingOrder) ?? 0) + 1;//oProductController.GenerateSortingOrder(); 

      db.tblProductInfos.InsertOnSubmit(otblProductInfo);//the InsertOnSubmit method called in the preceding code was named Add and the DeleteOnSubmit method was named Remove. 
      db.SubmitChanges(); 
      BindGridView(); 
      //oProductController.InsertAndSubmit(); 
      // ASPxGridView1.DataBind(); 
     } 

我的SQL語法

CREATE TABLE [dbo].[tblProductInfo](
    [intProductCode] [int] NOT NULL, 
    [strProductName] [varchar](100) NULL, 
    [SKU] [varchar](50) NULL, 
    [PACK] [varchar](50) NULL, 
    [intQtyPerCase] [int] NULL, 
    [mnyCasePrice] [money] NULL, 
    [intTBQtyPerCase] [int] NULL, 
    [bIsActive] [bit] NULL, 
    [intSortingOrder] [int] NULL, 
    [strProductAccCode] [varchar](max) NULL, 
CONSTRAINT [PK_tblProductInfo] PRIMARY KEY CLUSTERED 
(
    [intProductCode] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

,當我想插入,顯示我錯誤消息不支持指定的方法。 如何解決它。

回答

5

的「指定的方法不支持」錯誤消息當ASPxGridView嘗試調用其基礎DataSource的Update(Insert,Delete)命令時顯示,但未指定此命令。如果無法定義此命令,請處理RowUpdating(RowInserting,RowDeleting)事件,手動更新數據源(e.NewValues字典包含輸入值),最後將e.Cancel參數設置爲true並調用ASPxGridView.CancelEdit方法。

+0

請你發一些syntax.I想不是更新插入,比delete.If我設置e.Cancle = true對rowInserting方法,則rowInserted方法不起作用 – shamim 2010-07-12 18:14:49

+0

的確,E257的例子展示瞭如何使用這些事件。爲什麼你需要使用RowInserted事件?在你的情況下,不應該引發它,所有的代碼都應該在RowInserting事件處理程序中實現。 – 2010-07-12 19:40:05

+0

如果您流傳這個建議,最終會出現髒網格,數據庫已更改,但網格不顯示新記錄 – 2011-04-09 01:46:55

1

如果不使用數據源命令,那你可以使用網格RowUpdating事件規劃和設置e.Cancel = true,則調用grid.CancelEdit()方法(如上面的DevExpress團隊提到下面是一個例子:

 void grid_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) 
    { 
     // Your update logic here. 
     e.Cancel = true; 
     this.editableGrid.CancelEdit(); 
    } 
相關問題