我在rowdatabound事件中的某些单元格中放置了一个链接按钮。
我无法弄清楚如何在点击时从中检索行索引值。我在下面的几个版本中编写了链接按钮。
If e.Row.RowType = DataControlRowType.DataRow Then
Dim ParentLink As LinkButton = New LinkButton
If (e.Row.Cells(3).Text.Equals(" ")) Then
e.Row.Cells(3).BackColor = Drawing.Color.Red
ParentLink.Text = "Resend"
ParentLink.ID = "Resend"
ParentLink.CommandName = "Resend"
ParentLink.CommandArgument = e.Row.RowIndex.ToString()
' AddHandler ParentLink.Command, AddressOf resend_email
e.Row.Cells(5).Controls.Add(ParentLink)
End If
End If
我见过使用“asp:TemplateField>”,但是这样添加一个没有好的例子。当我点击它回到rowdatabound事件,但我不知道如何获得linkbutton的commandargument或rowindex。向这个年轻小伙子展示他的方式的错误!
答案 0 :(得分:0)
有效的最终代码段。
Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Resend" Then
Dim rowIndex = Convert.ToInt32(e.CommandArgument)
Dim Row = GridView1.Rows(rowIndex)
loc_resend = Row.Cells(4).Text ' location
custid_resend = Row.Cells(0).Text ' customer id
name_resend = Row.Cells(1).Text ' customer name
Ckbox_resend.Visible = True
butResend.Visible = True
End If
End Sub