在gridview rowcommand中获取BoundField值

时间:2011-04-11 09:57:31

标签: c# .net asp.net visual-studio gridview

我需要在gridview_rowcommand中获取所选列的绑定字段值。

有什么想法吗?

3 个答案:

答案 0 :(得分:5)

它会像......

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
row.Cells[0].Text

答案 1 :(得分:3)

它应该是这样的。

if (e.CommandName=="CommandName")
    {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = GridView1.Rows[index];
        string boundFieldText= row.Cells[0].Text;
    }

答案 2 :(得分:0)

要从网格视图中获取字段的值,首先设置datakeyname然后在default.aspx.cs页面中写下代码:

//this is for linkbutton onclick u can use button also
  ## Coding ## 

   protected void lnkDownload_Click(object sender, EventArgs e)
    {
         LinkButton lnkbtn = sender as LinkButton;
          GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
          string username= gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
    }