2011-01-22 4 views
5

"Edit Update Cancel"명령 필드가있는 gridview가 있습니다. 편집을 클릭하면 특정 행의 모든 ​​열이 편집 가능 해지고 업데이트를 클릭하면 표가 새 값을 기반으로 업데이트됩니다. 그런 다음 Gridview는 업데이트 된 데이터 테이블로 바인드됩니다. 그러나 여전히 "업데이트 취소"버튼이 남아 있습니다 . 행 일단 업데이트 후 정상 모드로 행을 작성해야합니다.

alt text

는 버튼을 "편집"어떻게하는 것이 가능하게되어 변경되어야한다 "업데이트 취소"업데이트되었습니다. 미리

덕분

protected void StaticNoticeGridView_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 

      try 
      {     
       //Gets the updated value from GridView 
       string id = StaticNoticeGridView.Rows[e.RowIndex].Cells[0].Text; 
       string updatedItem = e.NewValues[0].ToString(); 
       string updatedURL = e.NewValues[1].ToString(); 

       //Updated the Database 
       StaticNoticeController staticNoticeController = new StaticNoticeController(); 
       int rocordsAffected = staticNoticeController.UpdateStaticNoticeData(updatedItem, updatedURL, id); 

       //Gets the updated datatable and binds the Gridview again 
       if (rocordsAffected == 1) 
       { 
        this.StaticNoticeGridView.DataSource = null; 
        this.StaticNoticeGridView.DataSource = staticNoticeController.GetStaticNoticeData(); 
        this.StaticNoticeGridView.DataBind(); 
       } 
      } 
      catch(SystemException ex) 
      { 
       //ToDo: Log the Exception 
      } 
     } 
+0

코드를 보여주세요 전 업데이트 클릭 이벤트 핸들러에 사용합니다. – Hogan

+0

@Hogan Thanks .. 코드가 질문에 추가되었습니다. – Ananth

답변

11

세트 GridView1.EditIndex = -1 업데이트 된 데이터를 갱신하고 디스플레이하기위한 코드이며, 상기 방법에서 this.StaticNoticeGridView.DataBind();StaticNoticeGridView_RowUpdating

+0

빠른 응답 주셔서 감사합니다 – Ananth

+1

그 내 질문에 너무 대답했다, 내 목표가 아니었을 때라도 내 GridView 내 포스트 백에 편집 가능한 행을 보여주는 것이 약간 다른 문제가 있었다. 나는 왜 내가 전에이 문제를 겪어 보지 못했는지 모르지만, 적어도 지금은 내 대답을 가지고있다. 이것은 나를 미치게했다, 고마워! – dyslexicanaboko

관련 문제