vb.netのgridviewの画像ボタンから行のIDを取得します
-
20-08-2019 - |
質問
gridviewがあり、そのgridviewで、次のようにaddhandlerを使用してプログラムでimagebuttonsのリストを作成しました。
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
私の問題は、クリックハンドラーでクリックされた画像ボタンの行の値を取得することです。どうすれば入手できますか?
解決
割り当てることをお勧めします
imageButton.CommandName = "Delete"
imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get
そしてimageButton.OnCommandを使用して作業を行います。
編集: 手順は次のとおりです。
- RowCreatedで画像ボタンを作成
- RowDataBoundで画像ボタンのCommandNameとCommandArgumentを割り当てます
- RowCommandで、その行のイメージボタンCommandArgumentを確認すると、以前にそこに保存したIDが表示されます。
所属していません StackOverflow