『笔记』.Net中结合iBatisNet查询的DropDownList数据绑定

  其实标题中写iBatisNet查询有点特殊化的意味。其实DropDwonList控件可以接受很多种类的结果集作为他的数据源。比如Set、HashMap、IList。这里我是采用了iBatisNet中常用的IList结果集作为数据源的。
None.gif          private   void  Page_Load( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif

InBlock.gif            
if(!IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//构造当前时间
InBlock.gif
                this.txtTime.Text = ClassLib.getCurrentTime();
InBlock.gif
InBlock.gif                
//构造天气列表
InBlock.gif
                this.ddlWeather.DataSource = ClassLib.getWeatherList();
InBlock.gif                
this.ddlWeather.DataValueField = "Id";
InBlock.gif                
this.ddlWeather.DataTextField = "Weather";
InBlock.gif                
this.ddlWeather.DataBind();
InBlock.gif
InBlock.gif                
//按用户构造文章分类
InBlock.gif
                this.ddlCategory.DataSource = ClassLib.getCategoryList(ClassLib.getUserId());
InBlock.gif                
this.ddlCategory.DataValueField = "Id";
InBlock.gif                
this.ddlCategory.DataTextField = "Title";
InBlock.gif                
this.ddlCategory.DataBind();
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

  为了增加程序的封装性,我把对数据库的查询动作封装到了一个统一的全局类库中(ClassLib.cs)。这个文件中包含了几个查询动作。这里举例其一:
None.gif          // 得到天气列表
None.gif
         static   public  IList getWeatherList()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            IList listWeather 
= Mapper.Instance().QueryForList("SelectAll",null);
InBlock.gif            
return listWeather;
ExpandedBlockEnd.gif        }

None.gif
None.gif        
// 得到分类列表
None.gif
         static   public  IList getCategoryList( int  _userId)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            IList listCategory 
= Mapper.Instance().QueryForList("SelectByUserId", _userId);
InBlock.gif            
return listCategory;
ExpandedBlockEnd.gif        }

  绑定动作是很容易懂的。声明DropDownList的数据源DataSource,接着绑定结果集中的特定列到Value和Text就可以了。

转载于:https://www.cnblogs.com/viva/archive/2005/11/01/266063.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值