我是初學者,談到asp.net。我從昨天開始試圖找到一個問題的答案:如何使用asp.net將一個gridview的rownumber作爲命令參數傳遞?如何使用asp.net將gridview的rownumber作爲命令參數傳遞?
我已經嘗試了很多方法,但都沒有工作(commandargument在代碼隱藏中爲null),所以我認爲這是適當的嘗試使用JavaScript函數(如果有比使用JavaScript更短,更清晰的方法, 請告訴我)。
這裏的功能:
<script type = "text/javascript">
function GetSelectedRow(lnk) {
var row = lnk.parentNode.parentNode;
var rowIndex = row.rowIndex - 1;
alert("RowIndex: " + rowIndex);
return rowIndex;
}
</script>
而且也:
<ItemTemplate>
<asp:Label ID="labelStatus"
runat="server"
Text='<%#Bind("Statut")%>'
CommandArgument='<%#"Eval(GetSelectedRow(lnk))"%>'>
</asp:Label>
</ItemTemplate>
我需要的行號的原因是在OnRowCommand事件處理程序,以便能夠指定哪一行正在編輯。 (myGridView.EditIndex = Convert.Int16(e.CommandArgument.ToString());)。
預先感謝您:)
謝謝。但是我不明白CommandArgument在asp頁面中的顯式值歸屬在哪裏。這是我真正的問題:)我沒有找到如何將行號傳遞給命令參數。 – SunnyDay 2012-07-26 08:53:38
你不需要通過你的命令參數 – 2012-07-26 08:55:48