【问题标题】:Getting BoundField Value in gridview row_command在gridview rowcommand中获取BoundField值
【发布时间】:2011-04-11 09:57:30
【问题描述】:

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

有什么想法吗?

【问题讨论】:

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


    【解决方案1】:

    它会像......

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

    【讨论】:

    • 嘿伙计们,有一种方法。,实际上我在 gridview 中有一个链接按钮,我已经设置了 CommandArgument='' 并在行命令中我已经完成了., Convert.ToInt32(e.CommandArgument);我得到所选行的边界值。
    • 那么上述解决方案的问题是什么?
    【解决方案2】:

    应该是这样的。

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

    【讨论】:

      【解决方案3】:

      要从网格视图中获取字段的值,首先设置 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();
          }
      

      【讨论】:

        猜你喜欢
        • 2011-02-18
        • 2011-03-06
        • 1970-01-01
        • 1970-01-01
        • 2012-06-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-16
        相关资源
        最近更新 更多