现在的位置: 首页 > 综合 > 正文

读取数据库中值,将其设为select(下拉)控件选中值

2013年01月04日 ⁄ 综合 ⁄ 共 533字 ⁄ 字号 评论关闭
代码

                #region 读取数据库中值,将其设为select(下拉)控件选中值
//法一:
                foreach (ListItem li in sel_Department.Items)
                {
                    
if (li.Value.Trim() == sdr["Flag"].ToString().Trim())
                    {
                        li.Selected 
= true;
                        
break;
                    }
                }
//法二:
                ListItem li = sel_Department.Items.FindByValue(sdr["Flag"].ToString().Trim());
          if (li != null) li.Selected = true;//防止上语句FindByValue方法返回null对象
                
#endregion

 

抱歉!评论已关闭.