close

原本GridView就提供方法去取得引發命令的索引值
但是得仰賴繫結的物件中 的CommandArgument屬性

因此 如果萬一 你的CommandArgument屬性 自己去繫結了奇他的東西 例如 欄位的key值~ 或其他種種原因
你把她指定給其他值使用

那麼要取索引值時就尷尬了...

因此 我們可以透過其他方法去取得 引發事件的RowIndex

VB.net語法
Dim rowIndex As Integer = DirectCast(DirectCast(e.CommandSource, LinkButton).NamingContainer, GridViewRow).RowIndex
也可以用比較簡單的型別傳換Ctype
Dim index As Integer = CType(CType(e.CommandSource, LinkButton).NamingContainer, GridViewRow).RowIndex

C#語法
int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;

arrow
arrow
    全站熱搜

    ADOLPH 發表在 痞客邦 留言(0) 人氣()