Pergunta

Eu tenho um gridview e nesse gridview que eu criei uma lista de imagebuttons programaticamente com um AddHandler da seguinte forma:

Dim deletecshr As New ImageButton
deletecshr.ImageUrl = "\images\bttnDeletemini.gif"
deletecshr.ToolTip = "This Will Delete All Cashiers"
AddHandler deletecshr.Click, AddressOf deletecshr_Click
deletecshr.Attributes.Add("onclick", "javascript: if(confirm('Are you sure you want to delete all of these cashiers?')==false) return false;")

    If e.Row.Cells.Count > 2 And e.Row.RowType <> DataControlRowType.Header And e.Row.RowType <> DataControlRowType.Footer Then
        e.Row.Cells(3).Controls.Add(deletecshr)
    End If

meu problema está recebendo o valor da linha do imagebutton clicado no manipulador de clique. Como faço para conseguir isso?

Foi útil?

Solução

Eu recomendo atribuir

imageButton.CommandName = "Delete"
imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get

e, em seguida, usando o imageButton.OnCommand para fazer seu trabalho.

Editar: Aqui estão os passos a seguir:

  1. Crie o seu botão de imagem em RowCreated
  2. Atribuir o CommandName e CommandArgument do seu botão de imagem em RowDataBound
  3. Em RowCommand verificar a CommandArgument botões de imagem para essa linha e você deve ver o ID anteriormente armazenado lá.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top