(조건에 따라) gridview에서 행을 삭제하고 "master"gridview의 RowDataBound 이벤트 내부의 다른 gridview에 행을 추가하려고합니다. 원래는 .DeleteRow (i)를 호출하기 위해서는 "ondelete"이벤트 핸들러가 필요하다는 것을 몰랐습니다. 그러나 모든 gridview의 .DeleteRow 메서드가이 이벤트 처리기를 호출하므로 사용 방법에 관해 혼동 스럽습니다. 누군가가 올바른 방향으로 나를 가리 키도록 도와 줄 수 있습니까?gridview의 RowDataBound 이벤트에서 행을 삭제하는 방법
Protected Sub grdProduct_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdProduct.RowDataBound
' Grey out expired products
Dim row As GridViewRow
row = e.Row
Dim incomingDate As String
Dim incomingStatus As String = ""
incomingDate = row.Cells(3).Text.ToString()
incomingStatus = row.Cells(5).Text.ToString()
If (e.Row.RowType <> DataControlRowType.DataRow) Then
Exit Sub
End If
Try
Dim expDate As Date = incomingDate
If (expDate < DateTime.Today Or incomingStatus.Equals("D")) Then
'Create object for RowValues
Dim RowValues As Object() = {"", "", "", "", "", ""}
'Create counter to prevent out of bounds exception
Dim i As Integer = row.Cells.Count
'Fill row values appropriately
For index As Integer = 0 To i - 1
RowValues(index) = row.Cells(index).Text
Next
'create new data row
dProdRow = dProdtable.Rows.Add(RowValues)
dProdtable.AcceptChanges()
grdProduct.DeleteRow(e.Row.RowIndex)
End If
Catch ex As Exception
End Try
End Sub
Protected Sub grdProduct_Delete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles grdProduct.RowDeleting
'Not sure what to do here
End Sub
DeleteRow 메소드 대신 기본 그리드의 데이터 소스에서 행을 삭제하고 원하는 이벤트 (예 : CommandEvent 또는 Button-Click)에서 중첩 된 그리드의 소스에 추가 할 수 있습니다. 나중에'MainGrid.DataBind()'를 호출하면됩니다. –
RowDataBound 이벤트와 별도로 public 서브에서 선언 된 데이터 소스를 가지고 있습니다. 이 작업을 수행하기 위해 데이터 소스의 범위를 변경해야합니까? 불행히도 RowDataBound 이벤트를 사용하여 조건을 테스트해야합니다. – NealR