2012-01-25 5 views
2

나는 데이터 소스로 ASPxGridViewEntityDataSource을 사용합니다. EntityDataSource에서 "EnableInsert", "EnableUpdate"또는 "EnableDelete"를 true로 설정할 수 없으므로 CommandText를 작성합니다. 그래서 수동으로 데이터를 조작 (삽입, 업데이트, 삭제)합니다. 변경 사항은 수동으로 데이터베이스로 전달됩니다. 그러나의 GridView의 측면에서 이러한 오류가 주어진다 :이 컨트롤에 대한 삽입/업데이트/삭제가 비활성화되어 있습니다. EntityDataSource의 메시지

삽입 : 삭제 "Update is disabled for this control."
: 업데이트 "Insert is disabled for this control."
"Delete is disabled for this control."

가 어떻게이 문제를 해결할 수 있습니까?

는 (의 CommandText를 사용하는 이유는 어디에 매개 변수와의 GridView에 표시하기위한 1 개 이상의 테이블의 결합.)

+0

그 전후 (2012) EF가있는 ASPxGriView는 읽기 전용입니다. 열 단위 정렬조차도 작동하지 않기 때문에 훨씬 더 좋습니다. – Anderson

답변

1

먼저 테이블에서 차 ID가 있어야합니다, 당신은 삽입 할 수 있도록 형태로되어 있어야합니다 또는 이상적으로, 증가 키를 설정하고 값을 입력하는 것이 이상적입니다. 그런 다음 제어를 위해 value 속성을 설정해야합니다. 그리고 나서 작동 할 것입니다.

+0

이미 데이터를 삽입, 업데이트, 삭제합니다. 그러나 데이터를 조작 할 수는 있지만 오류가 발생합니다. 이제 트릭을 만들었습니다. 데이터를 편집 한 다음 마지막으로 "e.Cancel = true;"메서드를 호출합니다. 여기서 "e"는 "DevExpress.Web.Data.ASPxDataUpdatingEventArgs e"입니다. 그래서 gridview는 "ok 결과로 편집 작업이 취소되므로 오류를 줄 필요가 없습니다"라고 생각합니다. 즉, 공식적인 방식으로 문제를 해결하지 못했습니다. 까다로운 방법으로 해결했습니다. – Ypci

0

이 문제의 해결 방법을 만들었습니다. 있는 gridview에서 나는 템플릿 열 (내가 CommandArgument에 두 개의 인수를 전달하고있어)가 :

난 뒤에 코드 분할 CommandArgument과의 SelectedIndexChanged 이벤트를 사용하여 다음 변수에 값을 저장하고있는
<asp:TemplateField> 
        <ItemTemplate>       
         <asp:ImageButton ToolTip="Delete" ID="button4" ButtonType="Image" ImageUrl="~/Projectimages/img_del.png" Text="" CommandName="Select" CommandArgument='<%#Eval("ID") + ";" +"Delete"%>' runat="server"/> 
        </ItemTemplate> 
       </asp:TemplateField> 

:

string selectCommand = ""; 
    int selectCommandID = -1; 
    protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
     if (e.CommandName == "Select") 
     {     
      if (!e.CommandArgument.ToString().Contains(";")) 
       selectCommand = "Select"; 
      else 
      { 
       selectCommandID = Convert.ToInt32(e.CommandArgument.ToString().Split(';')[0]); 
       selectCommand = e.CommandArgument.ToString().Split(';')[1]; 
      } 
     }    
    } 

    protected void GridView_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (selectCommand == "Select") 
     { 
      //Select Code Here 
     } 
     else if (selectCommand == "Delete") 
     { 
      MyTestEntities context = new MyTestEntities(); 
      Table1 selectedRow = context.Table1.Single(a => a.ID == selectCommandID); 
      context.Table1.DeleteObject(selectedRow); 
      context.SaveChanges(); 

      EntityDataSource1.DataBind(); 
     } 
    } 

이 작동합니다. 이것을 사용하여 그리드 뷰 행을 업데이트 할 수도 있습니다.