在GridView中rowCommand行索引 [英] row index in gridview rowCommand
问题描述
只是想从变量传递价值诺特尔变量:
Just want to transfer value from variable to nother variable :
protected void gvVariableDetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = gvVariableConfig.Rows[index];
int rowIndex = index;
}
}
但rowIndex位置仍然有0值,指数得到了行值(在这些情况下,我尝试编辑第2行等指标值是1(由0开始))。所以希望有人知道如何索引值传送到rowIndex位置。
But rowindex still have zero value, and index got row value(in these case i try edit row 2 and so index value is 1(start by 0)). so hope anyone know how to transfer index value to rowIndex.
推荐答案
您可以使用 CommandSource
财产和投它的<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.control.namingcontainer.aspx\"><$c$c>NamingContainer$c$c>在 GridViewRow
。然后,你可以使用它的的rowIndex
属性:
You could use the CommandSource
property and cast it's NamingContainer
to the GridViewRow
. Then you can use it's RowIndex
property:
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int rowIndex = gvr.RowIndex;
如果你想使用 CommandArgument
您必须从ASPX设置:
If you want to use the CommandArgument
you have to set it from aspx:
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'
那么这也可以工作:
then this also works:
int RowIndex = int.Parse(e.CommandArgument.ToString());
这篇关于在GridView中rowCommand行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!