【问题标题】:Problem with getting a cell value OnRowCommand in Gridview在 Gridview 中获取单元格值 OnRowCommand 的问题
【发布时间】:2011-09-10 18:00:18
【问题描述】:
       protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = GridView1.Rows[index];

        k = row.Cells[0].ToString();
        Label1.Text = k;
 }

我想获取所选行中特定单元格的值。所以我尝试了这个,但这给出了非常奇怪的结果,标签打印下面的文本

     System.Web.UI.WebControls.DataControlFieldCell.

谁能告诉我如何解决我的问题。

【问题讨论】:

    标签: c# asp.net gridview gridviewcolumn


    【解决方案1】:

    使用 EventHandler Gridview_CellEdit 或类似的。然后如果 (selecteditems.count>0) 你可以得到它们的值。当然是创建一个新变量。

    【讨论】:

      【解决方案2】:

      试试这个:

      k = row.Cells[0].Text;
      

      你会得到其中的文字。

      【讨论】:

        【解决方案3】:

        将命令参数设置为

        CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>' CommandName = "QC"
        

        在 RowCommand 事件中

         if (e.CommandName == "QC")            
         {
             int RowIndex = Convert.ToInt32(e.CommandArgument);
        

        根据 RowIndex 获取你想要的值。

        【讨论】:

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