.Net中结合iBatisNet查询的DropDownList数据绑定
来源:互联网 发布:阿里云客服能赚钱吗 编辑:程序博客网 时间:2024/06/07 07:11
其实标题中写iBatisNet查询有点特殊化的意味。其实DropDwonList控件可以接受很多种类的结果集作为他的数据源。比如Set、HashMap、IList。这里我是采用了iBatisNet中常用的IList结果集作为数据源的。
为了增加程序的封装性,我把对数据库的查询动作封装到了一个统一的全局类库中(ClassLib.cs)。这个文件中包含了几个查询动作。这里举例其一:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
//构造当前时间
this.txtTime.Text = ClassLib.getCurrentTime();
//构造天气列表
this.ddlWeather.DataSource = ClassLib.getWeatherList();
this.ddlWeather.DataValueField = "Id";
this.ddlWeather.DataTextField = "Weather";
this.ddlWeather.DataBind();
//按用户构造文章分类
this.ddlCategory.DataSource = ClassLib.getCategoryList(ClassLib.getUserId());
this.ddlCategory.DataValueField = "Id";
this.ddlCategory.DataTextField = "Title";
this.ddlCategory.DataBind();
}
}
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
//构造当前时间
this.txtTime.Text = ClassLib.getCurrentTime();
//构造天气列表
this.ddlWeather.DataSource = ClassLib.getWeatherList();
this.ddlWeather.DataValueField = "Id";
this.ddlWeather.DataTextField = "Weather";
this.ddlWeather.DataBind();
//按用户构造文章分类
this.ddlCategory.DataSource = ClassLib.getCategoryList(ClassLib.getUserId());
this.ddlCategory.DataValueField = "Id";
this.ddlCategory.DataTextField = "Title";
this.ddlCategory.DataBind();
}
}
为了增加程序的封装性,我把对数据库的查询动作封装到了一个统一的全局类库中(ClassLib.cs)。这个文件中包含了几个查询动作。这里举例其一:
//得到天气列表
static public IList getWeatherList()
{
IList listWeather = Mapper.Instance().QueryForList("SelectAll",null);
return listWeather;
}
//得到分类列表
static public IList getCategoryList(int _userId)
{
IList listCategory = Mapper.Instance().QueryForList("SelectByUserId", _userId);
return listCategory;
}
static public IList getWeatherList()
{
IList listWeather = Mapper.Instance().QueryForList("SelectAll",null);
return listWeather;
}
//得到分类列表
static public IList getCategoryList(int _userId)
{
IList listCategory = Mapper.Instance().QueryForList("SelectByUserId", _userId);
return listCategory;
}
绑定动作是很容易懂的。声明DropDownList的数据源DataSource,接着绑定结果集中的特定列到Value和Text就可以了。
- .Net中结合iBatisNet查询的DropDownList数据绑定
- 绑定access数据库,asp.net 中 以DropDownList为查询条件 ,前台实现数据查询
- DataGrid中DropDownList 的数据绑定
- DataGrid中DropDownList 的数据绑定
- DropDownList 的数据绑定
- DropDownList的绑定数据
- asp.net中dropdownlist中绑定数据…
- ASP.NET中DropDownList控件的数据绑定的C#语言描述
- ASP.NET中dropdownlist 动态绑定数据的二种方法
- .net连接数据源以及dropdownlist的数据绑定
- DropDownList 控件 可编辑 查询 绑定数据
- 如何结合IbatisNet的LIST遍历实现模糊查询
- 如何结合IbatisNet的LIST遍历实现模糊查询
- DropDownList控件的数据绑定
- DropDownList的数据绑定方式
- DropDownList控件的数据绑定
- c# mvc 中 dropdownlist 的数据联动绑定
- ASP.NET MVC 八 DropDownList数据绑定
- 分页SQL语句 (转载)
- RACLE 常用的SQL语法和数据对象
- 嵌入式系统高级C语言编程
- setsockopt()用法
- db2 常用的SQL语法和数据对象
- .Net中结合iBatisNet查询的DropDownList数据绑定
- 环境监控中心GPRS实时监控系统
- 窗口滚动条
- 研究Google maps及51ditu的图片切割及存储方法(转)
- C#通用对话框
- Java中匿名内部类的作用
- JSPのライフサイクル
- oracle日期函数
- fromLatLngToPixel