【c# – 如何绑定转发器ItemDataBound,以在dropdownlist SelectedIndexChanged上更新】教程文章相关的互联网学习教程文章

C#_dropdownlist_2

string deptId =Request.Form["depts"].Trim(); Html.DropDownList()赋默认值: 页面代码如下: <% List<SelectListItem> list = new List<SelectListItem> { new SelectListItem { Text = "启用", Value = "0",Selected = true}, new SelectListItem { Text = "禁用", Value = "1" } }; %>//list储存dropdownlist的默认值 <%=Html.DropDownList("state",list,Model.st...

c# – ASP MVC DropDownList错误“转换为类型”【代码】

嘿,我有一个表有2个int类型的字段,它们是“StatusID”和“TypeID”. TypeID正常工作,但StatusID返回错误.这是我的控制器的样子:[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Project project) {var db = new DB();if (ModelState.IsValid){try{db.Projects.InsertOnSubmit(project);db.SubmitChanges();return RedirectToAction("Index");}catch{return View(project);}}ViewData["Status"] = from c in db.Statuss...

c#-如何在动态添加的DropDownList的ListItem上添加OnClick事件?【代码】

说我有以下代码:DropDownList changesList = new DropDownList();ListItem item;item = new ListItem();item.Text = "go to google.com";changesList.Items.Add(item);您如何动态地向项目添加OnClick事件,以便在单击该项目后访问google.com?解决方法:将此添加到您的代码:DropDownList changesList = new DropDownList();ListItem item; item = new ListItem(); item.Text = "go to google.com"; item.Value = "http://www.googl...

(asp.net c#)DropDownList绑定后显示对应的项的两种方法【图】

方法一: 实现代码 代码如下:DropDownList1.DataSource = listSort; DropDownList1.DataTextField = "LogSortName"; DropDownList1.DataValueField = "LogSortID"; DropDownList1.DataBind(); DropDownList1.SelectedIndex = ddl.Items.IndexOf(DropDownList1.Items.FindByValue("i")); //i要自己去获取你要显示的项的id。 方法二:我贴上部分代码 获取数据后 根据该value去配对你想要的项。 不过图中的for改成 do…while 应该会...

C#-DropDownList导致错误:对象引用未设置为对象的实例【代码】

我不断收到此错误,不知道为什么.我搜索并扫描了asp.net网站两天了,因此我需要一些帮助.错误是:Object reference not set to an instance of an object这是我的代码:DropDownList DropDownList1 =(DropDownList)ListView1.InsertItem.FindControl("DropDownList1");string highToLow = DropDownList1.SelectedValue; string lowToHigh = DropDownList1.SelectedValue;if (highToLow == "1") {var exmapleFilter = from users in t...

c#-从@ html.DropDownList返回int值【代码】

实际上,由于缺乏对ASP.NET-MVC 4的了解,我遇到了一些问题.我想做的是从下拉列表中获取选定的值,并将其返回给控制器(作为整数).让我更加困惑的是另一个正在返回字符串Value的DropDownList. 我的模特:public partial class PRODUCT {public int ID { get; set; }public string PRODUCT_NAME { get; set; }public int CATEGORY_ID { get; set; }public string LANGUAGE { get; set; } }public partial class PRODUCT_CATEGORY {publi...

C#-@ Html.DropDownList用于使用ViewBag SelectedListItem的所选项目不显示【代码】

我的代码如下: 控制器:foreach (Employee engineer in engineers) { if (!model.Customer.PrimaryEngineerId.Equals(engineer.EmployeeId)) {engineersListPrimary.Add(new SelectListItem { Text = engineer.FirstName + ' ' + engineer.LastName, Value = engineer.EmployeeId, Selected = false});}else{engineersListPrimary.Add(new SelectListItem { Text = engineer.FirstName + ' ' + engineer.La...

在C#中以gridview编辑模式填充dropdownlist的问题【代码】

我正在使用名为Country的列进行可编辑的Gridview,该列列出了这么长时间. 当我显示数据时,“国家”的值在“标签”中,但是当我选择“编辑”时,应显示“ DropDownList”以及国家列表.我能够显示列表.它应显示标签中所选择的国家. 我已经尝试过了,但是dropdownlist充满了System.Row.DataRowView,它也没有设置为以cvalue给出的SelectedValue aspx页面<asp:TemplateField HeaderText="Country"><ItemTemplate><asp:Label ID="lblCountry"...

C#-ASP.NET MVC 5 DropDownList可为空的int默认选项不为null【代码】

我对mvc DropDownList有问题,有很多关于此的主题,但没有一个问题相同. 我想为我的DropDownList选择默认的选项,但是我还需要其他选项来选择“所有”项目. 所以我的控制器将默认值2绑定到下拉列表public ActionResult Index(int? All = 2){ ...在cshtml中@Html.DropDownList("All","All items")所有列表都这样填充ViewData["All"] = new SelectList(CommonLists.property_types.Select(x => new { v = x.Value, t = x.Key.ToLower() ...

c#MVC Dropdownlist-没有类型为“ IEnumerable”的ViewData项,其键为“”【代码】

香港专业教育学院一直试图通过添加一个DropDownList到home / contact.cshtml来扩展以前的项目. 我的问题是在Firefox中加载页面时,我始终收到以下错误 错误:System.Web.Mvc.dll中发生类型为’System.InvalidOperationException’的异常,但未在用户代码中处理没有类型为“ IEnumerable”的ViewData项目具有键“ displayGraph” 我在另一个工作正常的页面上找到了另一个下拉列表(相同的方法),如果我将相同的代码复制到一个可以正常工...

c#-在DropDownList的选择更改时在Gridview中读取值【代码】

当在gridview内处理数据时,我真的很糟糕.在这里,我有一个简单的gridview,其中包含一个下拉列表,该下拉列表从数据库表Products中获取其数据.我想要的是在dropdownlist OnSelectedIndexChanged上,价格标签应读取dropdownlist中所选产品的价格.问题是当我在下拉列表中选择产品时,价格不显示.标签保持为空. ASP.NET<asp:GridView ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" PagerStyle-CssClass="p...

C# – DropDownList中的System.Data.DataRowView【代码】

我正在尝试使用列中的值填充下拉列表.现在的问题是:我没有在下拉列表中获得实际值(像印度(61)这样的国家代码).相反,我在下拉列表中获得“System.Data.DataRowView”(多次).public void bind(){DataSet ds1 = new DataSet();SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);con.Open();string strQuery = "select CountryCode from AUser";SqlCommand cmd = n...

c# – 如何在DropDownList中使用实体对象导航属性在我的强类型ASP.NET MVC上创建和编辑视图?【代码】

我有一个包含产品和系列类型的实体数据模型.每个产品都有一个系列. 我在ASP.NET MVC网站上使用此模型.我想在我的产品控制器的创建和编辑视图上使用Family DropDownLists. 如何在我的强类型ASP.NET MVC创建和编辑视图的DropDownList中使用实体对象导航属性? 以下代码失败… ProductController的:// POST: /Product/Create[AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Product p) {db.AddToProduct(p);db.SaveChange...

c# – DropDownList获取空白选择【代码】

我有一个直接来自数据库的代码填充的下拉列表.但是底部有一个没有价值的可选项.如何纯粹/完全绑定数据库中的数据以避免将来出现这种空白选择?protected void DropDownList_OnDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e){if (e.Row.RowType == DataControlRowType.Footer){DropDownList ddlName = (DropDownList)e.Row.FindControl("ddlName");ddlName.DataSource = MyClass.NameList();ddlName....

c# – Selenium 2 StaleElementReferenceException使用DropDownList和AutoPostBack使用InternetExplorerDriver时【代码】

我正在使用Selenium 2使用InternetExplorerDriver测试asp.net Web表单页面并遇到StaleElementReferenceException.该页面包含一个(自动回发)下拉列表,我从中选择不同的值. 示例代码: 页:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication.WebForm1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition...

SELECTEDINDEX - 相关标签