本文主要是介绍总结一下DataSet数据集ds和GridView的所有行遍历的方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
通常我们为了针对数据表中的每一行进行数据处理,那么,之前应该也看到过。这里不厌其烦地来重复一下:
(1)DataSet数据集的遍历:
DataSet ds = B_FileBorrowListManager.Getlist(txtDate1.Text.Trim(), txtDate2.Text.Trim()
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
ds.Tables[0].Columns.Add("NAME", typeof(string));
foreach (DataRow dr in ds.Tables[0].Rows) //DataRow类型
{
if (dr["Id_ApplyMan"] != DBNull.Value)
{
dr["NAME"] = B_FileBorrowListManager.GetManNameById(decimal.Parse(dr["Id_ApplyMan"].ToString()));
}
}
ViewState["Gv1"] = ds;
}
(2)GridView数据表中的遍历
GridViewRow gvr = (GridViewRow)((DataControlFieldCell)(((LinkButton)(sender)).Parent)).Parent; //索引当前行,点击LinkButton时候实现
//选中行标注颜色
foreach (GridViewRow gvr1 in GridView1.Rows) //GridViewRow类型
{
gvr1.BackColor = System.Drawing.Color.Empty;//没有颜色,透明
}
gvr.BackColor = (System.Drawing.Color)(new System.Drawing.ColorConverter()).ConvertFromString("#9900FF");
//LinkButton lbt = (LinkButton)sender;
//DataControlFieldCell dcf = (DataControlFieldCell)lbt.Parent;
//GridViewRow gvr= (GridViewRow)dcf.Parent;
decimal id = decimal.Parse(gvr.Cells[0].Text.Trim());
}
这篇关于总结一下DataSet数据集ds和GridView的所有行遍历的方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!