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

关于DataTable的,高手来帮帮忙
C# code
 AccountInfoBLL bll = new AccountInfoBLL();
        DataTable dt= bll.GetAccountById(id);
        DataTable sdt = bll.BindStageDropDownList();
        for (int i = 0; i < sdt.Rows.Count; i++)
        {
            
        }


GetAccountById这个方法是根据Id得到一个数据表,BindStageDropDownList这个方法是绑定下拉列表框的数据表。我调用GetAccountById这个方法得到dt时,dt里面有个站点类型,我想要拿dt里的站点类型跟sdt这个里面的站点类型去比较,如果有就默认选中,代码怎么写啊

------解决方案--------------------
C# code
AccountInfoBLL bll = new AccountInfoBLL();
        DataTable dt= bll.GetAccountById(id);
        DataTable sdt = bll.BindStageDropDownList();
        for (int i = 0; i < sdt.Rows.Count; i++)
        {
            for(int j = 0; j < sdt.Rows.Count; j++)            
                if(dt.Rows[i]["Type"].ToString()==sdt.Rows[i]["Type"])
        }

------解决方案--------------------
C# code

        for (int i = 0; i < sdt.Rows.Count; i++)
        {
            for (int j = 0; j < dt.Rows.Count; j++)
            {
              //这里比较吧,比如
                      if (dt.Rows[j].Cells[0].Value.ToString() ==            sdt.Rows[i].Cells[0].Value.ToString())
                      {
                      //选中
                      } 
            }
        }