只想将值从变量传递到nother变量:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是rowindex仍然没有值,索引得到了行值(在这种情况下我尝试编辑第2行,所以索引值是1(从0开始)).所以希望有人知道如何将索引值传递给rowIndex.
Tim*_*ter 16
您可以使用该CommandSource属性并将其NamingContainer转换为GridViewRow.然后你可以使用它RowIndex属性:
GridViewRow gvr = (GridViewRow)((Control)e.CommandSource).NamingContainer;
int rowIndex = gvr.RowIndex;
Run Code Online (Sandbox Code Playgroud)
如果你想使用CommandArgument你必须从aspx设置它:
CommandArgument='<%# ((GridViewRow) Container).RowIndex %>'
Run Code Online (Sandbox Code Playgroud)
那么这也有效:
int RowIndex = int.Parse(e.CommandArgument.ToString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39119 次 |
| 最近记录: |