从gridview更新列视图

时间:2014-01-28 09:06:08

标签: sql vb.net gridview

SELECT  
    matno,
    MAT_NAME,
    rawpkgno,
    MAX(SWITCH(deldate=? ,ORDCASES )) AS [CURRDATE],
    MAX(SWITCH(deldate=? ,ORDCASES )) AS [previous_day],
    MAX(SWITCH(deldate=? ,ORDCASES )) AS [Last_date]
FROM 
    invorder
WHERE
    invorder.strno =54009
    OR [invorder.deldate] IS NULL
GROUP BY
    matno,
    MAT_NAME,
    rawpkgno

我在网格视图中的输出如下

matno    MAT_NAME     rawpkgno       CURRDATE     previous_day      Last_date
Edit      1          REGULAR BUNS      0             125                  11
Edit      3          BIG MAC BUNS      0              29    
Edit      4          MAC FRIES        551             28

现在,当我选择编辑时,我应该能够编辑 CURDATE 。如果有人能帮我这么做我能做到吗?

1 个答案:

答案 0 :(得分:0)

在你的aspx.cs页面中这样做

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    string query = string.Empty;
    string id = GridView1.DataKeys[e.RowIndex].Values["MAT_Name"].ToString();       
    TextBox CURRDATE = GridView1.Rows[e.RowIndex].FindControl("txtCURRDATE") as TextBox;

    GridView1.EditIndex = -1;
    con.Open();

    SqlCommand cmd = new SqlCommand("update tableName set CURRDATE='" + CURRDATE.Text + "' where MAT_Name='" + id + "'", con);
    cmd.ExecuteNonQuery();
    con.Close();
   // here you bind your gridview
}

并取消该更新

 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
    GridView1.EditIndex = -1;
    //Bind gridview       
}

或者您也可以参考该链接

http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html