GridView的表头如下:
                              订单信息    发运信息   出库信息   发票信息 
客户名称 存货名称 存货规格 ----------------------------------------------
                           数量 均价 金额 数量 金额 数量 金额  数量 金额 
这个表头是我处理而得到的,真正的还有另一个表头,但被隐藏起的。
现在我想取某列的值,如下:
protected void gvContract_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Order")
            {
                    Response.Write("名称"+gvContract.Rows[Convert.ToInt16(e.CommandArgument)].Cells[0].Text.ToString() + "物资" + gvContract.Rows[Convert.ToInt16(e.CommandArgument)].Cells[1].Text.ToString() );
             }
         }
现在的情况是,到表头第二列的值是可以取到的,当怎么也取不到第一列的值,那位大侠指点下?

解决方案 »

  1.   

    CommandArgument='<%# Container.DataItemIndex + 1 %>' 
    e.CommandArgument
    GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Value
    GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];     
          
    模板列
     Control cmdControl = e.CommandSource as Control; 
     row = cmdControl.NamingContainer as GridViewRow;
    是否设置问题
      

  2.   

    要取到隐藏列的值,可以先把该列的visible属性设为true来取,然后在将其设为false隐藏起来,