2013-04-15 2 views
1

나는 ASP.net 프로젝트로 작업하고 있고 datasource로 SQL 데이터베이스에서 데이터 집합이있는 gridview 있습니다.gridview 가져 오기 열 머리글 편집 후

gridview에서 값을 변경할 때 해당 데이터 집합을 사용하여 데이터베이스를 다시 업데이트 할 수 있도록 데이터 집합을 업데이트하고 싶습니다.

나는 지금까지 가지고있는 진술.

문제가있는 부분입니다. 선택한 행을 가져올 수 있지만 선택한 열 이름을 사용하여 데이터 집합을 업데이트 할 수 없습니다.

myDataSet.Tables[0].Rows[e.RowIndex][?] = ""; 

RowUpdating 이벤트의 전체 코드.

protected void grdViewDetails_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 
       //Just get the dataset populated from my database (sql) 
       DataSet dsOriginal = dbConn.returnSqlDataset(query); 

       //update the dataset here so that you can update the database again. 
       foreach (TableCell cell in grdViewDetails.Rows[e.RowIndex].Cells) 
       { 
        //set the employeeid so you can update the dataset 
        if (cell.Controls[0] is TextBox) 
        { 
         TextBox textbox = (TextBox)cell.Controls[0]; 
         string value = textbox.Text; //This is just a tester to see if the value is correct 
        // dsOriginal.Tables[0].Rows[e.RowIndex][?] = value; //Here is the problem, how to get the selected column name 

        } 
        else 
        { 
         if (cell.Controls[0] is CheckBox) 
         { 
          CheckBox chkBoxWeek = (CheckBox)cell.Controls[0]; 
          Boolean checkStatus = chkBoxWeek.Checked; //This is just a tester to see if the value is correct 
          //dsOriginal.Tables[0].Rows[e.RowIndex][?] = checkStatus; //Here is the problem, how to get the selected column name 
         } 
        } 
       } 

       //Use the updated dataset to update the database with. 
       dbConn.udpatCourse(dsOriginal); 


      } 

답변

1
당신은 업데이트 된 내용을 알아 내기 위해 GridViewUpdateEventArgs.NewValues 컬렉션을 반복 할 수

.

이 약간 연결 MSDN 문서에서 적응 : 내가 제대로 질문을 읽고 있어요 경우

foreach (DictionaryEntry entry in e.NewValues) 
{ 
    string columName = entry.Key; 
    string userInput = e.NewValues[entry.Key]; 
    // Now you can do stuff with this info that meets your logic needs 
} 

, 당신은 당신이 여기에서 필요한 것을 얻을 수 있어야합니다.

관련 문제