But how could you live and have no story to tell!
访问统计 original graphics

解决这个问题有好几个方法:
1 加RowCommand事件中,判断请求的发出按钮控件名,根据传递的参数来获取当前行中我们需要的参数。
2 GridView设置datakeynames方式。

   //获得DataKeys的值
   GridView1.DataKeys[e.Row.DataItemIndex].Values[0];

3、今天给大家介绍一种最方便,也最满足日常思维的好办法:
    采用控件事件的sender的Parent来获取cell对象,再取cell的上级对象,也就是row对象了。简单吧!

    在GridView中放了一个模板列,添加一个按钮名字设置为btnAdd,双击该按钮,进入添加按钮事件。
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        DataControlFieldCell dcf = (DataControlFieldCell)btn.Parent;
        GridViewRow gvr = (GridViewRow)dcf.Parent;

        Response.Write(gvr.Cells[i].Text.ToString());
        //"i"代表要取的列的值。
    }

posted on 2008-06-24 10:15  nextsoft  阅读(1104)  评论(0编辑  收藏  举报