日期:2014-05-17  浏览次数:20782 次

c# gridview的用法
我在gridview上面加了一个ButtonFiled,给它绑定字段为“邮寄状态”,我想做的是,点击该按钮,就把当前的这个邮寄状态改为 “yes”

这个怎么写代码?

还有数据源有手动绑定吗?



------解决方案--------------------
设置按钮的CommandName = "fh";
然后在下面事件中写代码

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (!(((Control)e.CommandSource).Parent.Parent is GridViewRow)) return;
        GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
        int id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
        using (SqlConnection con = new SqlConnection(Common.ConnectionString))
        {
            string sql = string.Empty ;
            if (e.CommandName == "fh")
            {
                //这里写update代码
            }
        }
    }