datagrid移除行 请教:有一个分页的datagrid,如何删除datagrid中的一行,但并不删除数据库中的记录。如何实现呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 从datasource里移除数据然后重绑定 把你绑定gridview的代码发来看看 public void BindGrid() { //将将M_EBOOK_SERIAL表中的数据绑定在在dgList上DbHand dbHand = new DbHand(); DbHand dbHand = new DbHand(); DataSet ds = new DataSet(); DataSet dsCurEbook = new DataSet(); string strSql = ""; string strCurBook = ""; strSql = " select ebook_no, bkc, ebook_serial,start_date, bkc_descr, hs_code "; strSql = strSql + " from m_ebook_serial "; strSql = strSql + " order by ebook_no, ebook_serial asc"; try { dbHand.OpenConnection(); ds = dbHand.ReadData( strSql, "ebook_list"); dgList.DataSource = ds.Tables["ebook_list"].DefaultView; this.dgList.DataBind(); lblCurrentIndex.Text = "第 " + (dgList.CurrentPageIndex + 1).ToString() + " 页"; lblPageCount.Text = "总共 " + dgList.PageCount.ToString() + " 页"; } catch( System.Exception ex ) { lblMsg.Text = ex.Message.ToString().Trim(); } finally { dbHand.CloseConnection(); } } public void Remove(int iRowIndex) { //将将M_EBOOK_SERIAL表中的数据绑定在在dgList上DbHand dbHand = new DbHand(); DbHand dbHand = new DbHand(); DataSet ds = new DataSet(); DataSet dsCurEbook = new DataSet(); string strSql = ""; string strCurBook = ""; strSql = " select ebook_no, bkc, ebook_serial,start_date, bkc_descr, hs_code "; strSql = strSql + " from m_ebook_serial "; strSql = strSql + " order by ebook_no, ebook_serial asc"; try { dbHand.OpenConnection(); ds = dbHand.ReadData( strSql, "ebook_list"); ds.Tables["ebook_list"].rows.remove(ds.Tables["ebook_list"].rows[iRowIndex]); //这样来移除数据 dgList.DataSource = ds.Tables["ebook_list"].DefaultView; this.dgList.DataBind(); lblCurrentIndex.Text = "第 " + (dgList.CurrentPageIndex + 1).ToString() + " 页"; lblPageCount.Text = "总共 " + dgList.PageCount.ToString() + " 页"; } catch( System.Exception ex ) { lblMsg.Text = ex.Message.ToString().Trim(); } finally { dbHand.CloseConnection(); } } 对于分页的datagrid来说,这个iRowIndex如何取得呢?我用e.Item.ItemIndex是当前页上的行号。这样移除数据对否? ds.Tables["ebook_list"].rows.remove(ds.Tables["ebook_list"].rows[iRowIndex]); 这一句的操作对象是table,这个不存在分页情况,和gridview没关系....你就是直接移除了table的这一行....建议根据主键找到那条数据,在table里移除掉,再绑定 这个意思我明白了,但是我想获取的是datagrid当前绑定的数据表,而不是每次都从数据库去取得表。如何能获取到datagrid当前所绑定的数据表的内容呢? 看看这里有没有你需要哒,个人收集的DATAGRID资料大全,满意的话,给个分吧DataGrid的EditCommandColumn怎么使用图片作为按钮Asp.net的DataGrid怎么纵向显示数据Asp.net的DataGrid中怎么用联合主键的DataKeys定位记录Asp.net的DataGrid为什么取不到值Asp.net的DataGrid在PostBack后怎么定位记录Asp.net怎么触发DataGrid模板列中控件的事件怎么在绑定后动态改变DataGrid中的内容Asp.net中DataGrid利用DataRelation显示主从表信息ASP.NET中DataGrid和DataList控件用法比较Asp.net创建跨多列以及多行表头的DataGridAsp.net为DataGrid整行添加服务器事件代码更多Asp.net DataGrid js填充的select如何在后台取值 .net mvc3 不同 Action下的共用一个View 如何取得日期中的年份? .net2.0怎么生成静态页面?? 在线等高人啊!~ Visual Studio 智能双引号 asp.net修改密码 请问这代码怎么分! 在a标签中加入class样式后,href就没法用了,是什么个原因。 请高手指导!万分感激!关于DataGrid中行选定的方法!(有挑战性) .NET頁面跳轉 gridview 绑定数据表
然后重绑定
{
//将将M_EBOOK_SERIAL表中的数据绑定在在dgList上DbHand dbHand = new DbHand(); DbHand dbHand = new DbHand(); DataSet ds = new DataSet();
DataSet dsCurEbook = new DataSet(); string strSql = ""; string strCurBook = ""; strSql = " select ebook_no, bkc, ebook_serial,start_date, bkc_descr, hs_code ";
strSql = strSql + " from m_ebook_serial ";
strSql = strSql + " order by ebook_no, ebook_serial asc"; try
{
dbHand.OpenConnection(); ds = dbHand.ReadData( strSql, "ebook_list"); dgList.DataSource = ds.Tables["ebook_list"].DefaultView;
this.dgList.DataBind();
lblCurrentIndex.Text = "第 " + (dgList.CurrentPageIndex + 1).ToString() + " 页";
lblPageCount.Text = "总共 " + dgList.PageCount.ToString() + " 页";
}
catch( System.Exception ex )
{
lblMsg.Text = ex.Message.ToString().Trim();
}
finally
{
dbHand.CloseConnection();
} }
public void Remove(int iRowIndex)
{
//将将M_EBOOK_SERIAL表中的数据绑定在在dgList上DbHand dbHand = new DbHand(); DbHand dbHand = new DbHand(); DataSet ds = new DataSet();
DataSet dsCurEbook = new DataSet(); string strSql = ""; string strCurBook = ""; strSql = " select ebook_no, bkc, ebook_serial,start_date, bkc_descr, hs_code ";
strSql = strSql + " from m_ebook_serial ";
strSql = strSql + " order by ebook_no, ebook_serial asc"; try
{
dbHand.OpenConnection(); ds = dbHand.ReadData( strSql, "ebook_list");
ds.Tables["ebook_list"].rows.remove(ds.Tables["ebook_list"].rows[iRowIndex]); //这样来移除数据
dgList.DataSource = ds.Tables["ebook_list"].DefaultView;
this.dgList.DataBind();
lblCurrentIndex.Text = "第 " + (dgList.CurrentPageIndex + 1).ToString() + " 页";
lblPageCount.Text = "总共 " + dgList.PageCount.ToString() + " 页";
}
catch( System.Exception ex )
{
lblMsg.Text = ex.Message.ToString().Trim();
}
finally
{
dbHand.CloseConnection();
} }
我用e.Item.ItemIndex是当前页上的行号。这样移除数据对否?
这一句的操作对象是table,这个不存在分页情况,和gridview没关系....你就是直接移除了table的这一行....
建议根据主键找到那条数据,在table里移除掉,再绑定
如何能获取到datagrid当前所绑定的数据表的内容呢?
DataGrid的EditCommandColumn怎么使用图片作为按钮
Asp.net的DataGrid怎么纵向显示数据
Asp.net的DataGrid中怎么用联合主键的DataKeys定位记录
Asp.net的DataGrid为什么取不到值
Asp.net的DataGrid在PostBack后怎么定位记录
Asp.net怎么触发DataGrid模板列中控件的事件
怎么在绑定后动态改变DataGrid中的内容
Asp.net中DataGrid利用DataRelation显示主从表信息
ASP.NET中DataGrid和DataList控件用法比较
Asp.net创建跨多列以及多行表头的DataGrid
Asp.net为DataGrid整行添加服务器事件代码
更多Asp.net DataGrid