2017-07-11 12 views
0

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イベントに戻りますが、リンクボタンのコマンド引数または行インデックスを取得する方法はわかりません。この若い子に自分の道の誤りを見せてください!

答えて

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 
関連する問題