在rowcommand中获取gridview列的值

时间:2017-06-01 05:38:50

标签: c# asp.net gridview

这是我尝试过但我为job_Name

获取null
 GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

 int RowIndex = row.RowIndex; // this find the index of row

 string job_Name = row.Cells[1].Text;

job_Namenull

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

private void RowCommand(object sender, GridViewCommandEventArgs e)
{
    var grid = sender as GridView;
    if (grid == null)
    {
        return;
    }

    var  index = Convert.ToInt32(e.CommandArgument);
    var row = grid.Rows[index];
    string job_Name = row.Cells[1].Text;
}