我的GridView上有一個刪除按鈕。點擊刪除按鈕後,該行應完全從會話中刪除 。我目前做如下:從數據集中完全刪除一行
protected void gvMainLog_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Remove")
{
GridViewRow rowSelect = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
int rowindex = rowSelect.RowIndex;
DataSet ds = ((DataSet)Session["old"]);
ds.Tables[0].Rows[rowindex].Delete();
Session["old"] = ds;
gvMainLog.DataSource = Session["old"];
gvMainLog.DataBind();
}
的問題是:
ds.Tables[0].Rows[rowindex].Delete();
僅刪除該行中的內容。當我看數據集時,它顯示一個空行。
有沒有辦法刪除整行,沒有顯示空行?
你試過datarow.Remove()嗎? http://msdn.microsoft.com/en-us/library/system.data.datarowcollection.remove.aspx – Zaki
你可以試試[Remove](http://msdn.microsoft.com/en-us/library/ DataRowCollection對象的system.data.datarowcollection.remove.aspx)方法。 – GunnerL3510