MVC2.0:Html. DropDownList绑定数据库中的字段
来源:互联网 发布:three.js视频教程 编辑:程序博客网 时间:2024/06/05 08:50
MVC2.0:Html. DropDownList---
DropDownList心得体会:
目的:要从数据库中查询两个字段绑定到DropDownList,当我们点击按钮时弹出隐藏的字段值,并把字段值赋给文本框
字段一:PersonID-----隐藏的字段
字段二:FirstName----需要显示出来的字段
说明:代码已经给出,数据库需要自己整一个表:要使用ADO.Net Entity framework
前台界面.aspx代码:
<%=Html.TextBox("hello")%>
<%=Html.DropDownList("drop") %>
<input type="button" id="get1" onclick="Person/GetPer" />
Js代码:
<script type="text/ecmascript">
//点击按钮触发的事件
$(function() {
$("#get1").click(function () {
vardata = $("#drop").val();//得到DropDownList隐藏的值
$("#hello").val(data);//把得到的值赋给文本框
alert(data);//弹出文本框展示隐藏的值
returntrue;
})
})
</script>
.cs代码:
///
///从表中查询所要得到所有数据集合
public static List<object>GetList()
{
using(DataContext dataContext = new DataContext())
{
varpersonList = dataContext.People.Select(p => new{ PersonID = p.PersonID, FirstName = p.FirstName }).ToList();
List<object> result = newList<object>();
foreach(var p inpersonList)
{
result.Add(new
{
personID = p.PersonID,
FirstName = p.FirstName
});
}
returnresult;
}
}
//调用此方法GetList():
//---------------------------------------------------
public ActionResultGetPer()
{
List<object> per = GetList();//调用底层方法
//绑定字段到DropDownList-
ViewData["drop"]= new SelectList(per,"personID", "FirstName");
returnView();
}
- MVC2.0:Html. DropDownList绑定数据库中的字段
- MVC2 Html.DropDownList数据绑定
- DropDownList 绑定数据库中的字段获取下拉列表值
- DropDownList 绑定数据库中的字段获取下拉列表值
- DropDownList 绑定数据库中的字段获取下拉列表值
- dropdownlist绑定数据库字段的实现
- DropDownList绑定数据库中多个字段的值
- DropDownList绑定显示数据库多个字段
- 关于DropDownList绑定到数据库中的方法
- MVC DropdownList 怎么绑定数据库中的值
- DropDownList 绑定数据库
- DropDownList绑定数据库
- DropDownList控件绑定数据库
- DropDownList和数据库绑定实例
- 绑定DropDownList的中的值
- MVC2.0中的HtmlHelper大全
- 使用Gridview绑定数据库中的图片(Image字段)
- DropDownList中的选项是从数据库中绑定的,但是如何在前面添加“请选择”?
- 我的2011之蜕变
- Xcode JumpToDefinition failed with symbol not found
- SqlServer2000安装程序检测出uninstallshield正在使用中,请关闭uninstallshield并重新启动安装程序,错误432.
- javascript 过滤空格
- .Net面试基础问答:抽象类和接口的区别?
- MVC2.0:Html. DropDownList绑定数据库中的字段
- Spring,hibernate数据库连接配置
- Qt中文编码
- 关于ID变成ctl00$开头问题
- 【Linux】GNU CC 使用
- SurfaceView和View最本质的区别
- 对计算机系学生的七个建议
- 用户对社交杂志阅读应用Flipboard的三点抱怨
- JTable