2013-07-09 1 views
0

GridView에서 편집 단추를 누른 특정 데이터를 특정 열에서 어떻게 가져 옵니까?GridView에서 해당 행의 편집을 누르면 특정 열의 데이터를 가져옵니다.

다음 코드 나던 작업 :

protected void viewStoryTime_OnRowEditing(object sender, GridViewEditEventArgs e) 
{ 
    SqlDataSource10.UpdateParameters["setEditHoursParam"].DefaultValue = viewStoryTime.SelectedRow.Cells[0].Text; 
} 

행이 실제로 선택하지 않은 때문이다. 이것을 어떻게 할 수 있습니까?

+0

흥미로운 임 찾고 :

당신은 수 매개 변수 GridViewCommandEventArgs 명령 이름을 전달하는 RowCommand 이벤트를 구현할 수있는이

SqlDataSource10.UpdateParameters["setEditHoursParam"].DefaultValue = MyGridView.Rows[e.NewEditIndex].Cells[0].Text; 

또 다른 방법 같은 것을해야, 다음과 같이해야합니다 이 답변을 얻으려면 MVC를 사용하면 링크와 함께 ID를 전달할 수있는 위치를 매우 쉽게 만들 수 있습니다. – meda

답변

1

매개 변수 GridViewEditEventArgs에는 Gridview의 현재 편집 된 행에 대한 행 인덱스가 들어 있습니다.

void MyGridView_RowCommand(Object sender, GridViewCommandEventArgs e) 
{ 
    // If multiple buttons are used in a GridView control, use the 
    // CommandName property to determine which button was clicked. 
    if(e.CommandName=="my command name") 
    { 
    //Do stuff here 
    } 
} 
2

e.NewEditIndex에는 현재 편집중인 행의 색인이 있습니다. 이를 사용하여 행에 액세스하고 필요에 따라 셀 데이터를 읽을 수 있습니다.

관련 문제