asp.net 列表信息列表怎么做

aspnet网页间传信息方法大全_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
aspnet网页间传信息方法大全
上传于|0|0|文档简介
&&各种实现网页间传递消息的方法,使用asp.net技术
你可能喜欢asp.net联动列表框_百度百科
声明:百科词条人人可编辑,词条创建和修改均免费,绝不存在官方及代理商付费代编,请勿上当受骗。
asp.net联动列表框
本词条缺少概述、名片图,补充相关内容使词条更完整,还能快速升级,赶紧来吧!
asp.net联动列表框简介
另类无、联动下拉列表框(二级+XMLHttpRequest)
二级的联动下拉列表,从思路上讲,大致分下列几步:
一:触发第一个下拉列表的onchange事件。
二:处理页后,会返回处理请求后的信息(服务器端用Response.Write方法写入要返回的字符串,客户端用responseText属性接收字符串。
三:用得到的字符串处理后更新第二个下拉列表框
asp.net联动列表框主要代码
一:建立读取XML的类,这里也可以是数据库的查询
public class ReadXmlCS
public const string k = &|&;
public const string s = &,&;
public ReadXmlCS()
// TODO: 在此处添加构造函数逻辑
public static string QueryXml(string filename,string querystr)// @&//Pro_class/@id&
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.Xml.XPath.XPathDocument myXPathDocument = new System.Xml.XPath.XPathDocument(filename);
System.Xml.XPath.XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
System.Xml.XPath.XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select(querystr);
while(myXPathNodeIterator.MoveNext())
sb.Append(myXPathNodeIterator.Current.Value.ToString() +&,&);//把属性值添加到字符串末尾,添加分组字符“,”
System.Xml.XPath.XPathNavigator myXPathNavigator2 = myXPathNodeIterator.Current.Clone();//克隆当前接点
while(myXPathNavigator2.MoveToNextAttribute())//移动指针到下一个属性
sb.Append(myXPathNavigator2.Value.ToString()+&|&);//把属性值添加到字符串末尾,添加分组字符“|”
myXPathNavigator2.MoveToNextAttribute();
sb.Append(myXPathNavigator2.Value.ToString()+&|&);
return sb.ToString();
public static void QueryXml(string filename,string querystr,System.Web.UI.WebControls.DropDownList dd)// @&//Pro_class/@id&
System.Xml.XPath.XPathDocument myXPathDocument = new System.Xml.XPath.XPathDocument(filename);
System.Xml.XPath.XPathNavigator myXPathNavigator = myXPathDocument.CreateNavigator();
System.Xml.XPath.XPathNodeIterator myXPathNodeIterator = myXPathNavigator.Select(querystr);
while(myXPathNodeIterator.MoveNext())
System.Web.UI.WebControls.ListItem li = new System.Web.UI.WebControls.ListItem();
li.Value = myXPathNodeIterator.Current.Value.ToString() ;//把属性值(id)添加到ListItem的“值”属性
System.Xml.XPath.XPathNavigator myXPathNavigator2 = myXPathNodeIterator.Current.Clone();//克隆当前接点
while(myXPathNavigator2.MoveToNextAttribute())//移动指针到下一个属性
li.Text = myXPathNavigator2.Value.ToString();//把属性值(title)添加到ListItem的“”属性
myXPathNavigator2.MoveToNextAttribute();
li.Text = myXPathNavigator2.Value.ToString();
dd.Items.Add(li);
其中关键的步骤加了注释,其它的大家可以到MSDN上去查找。
二。实现 (WebForm8.aspx.cs页面):
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList Dropdownlist1;
private void Page_Load(object sender, System.EventArgs e)
// 在此处放置用户代码以初始化页面
string str = this.Request.QueryString[&querychild&];
if((str != null) && (str == &yes&))
string querystr = &//Pro_class[& + this.Request[&parentid&] + &]/Pro_class_small/@id&;
string show = zlp.str.ReadXmlCS.QueryXml(@&D:\Inetpub\wwwroot\zlp\XmlData\ProductMenu.xml&,querystr);
this.Response.Write(show);
this.Response.End();
if(!this.IsPostBack)
this.BindDropDownList();//加载页面时,填充第一个下拉列表框
protected void BindDropDownList()
this.Dropdownlist1.Attributes.Add(&onchange&,&javascript:XmlPost(this);&); //服务器端添加属性
zlp.str.ReadXmlCS.QueryXml(@&D:\Inetpub\wwwroot\zlp\XmlData\ProductMenu.xml&,@&//Pro_class/@id&,this.Dropdownlist1);如何增加Asp.Net Core生成的模板网站中用户信息表中的列(AspNetUsers)
时间: 13:27:12
&&&& 阅读:121
&&&& 评论:
&&&& 收藏:0
标签:环境:
1.VS2015 Community 14.0.25431.01 Update 3;
2.其他环境(具体哪一个影响不太清楚,都列在这儿)
使用的系统模板
利用系统提供的模板,并选择个人身份验证。如图:
模板提供的身份认证数据库中的AspNetUsers表,需要根据需要增加列。以下图为例,绿色框中的列都是模板默认的,我要增加一列(以Test为例)。
解决过程:
&&&&&&& 刚刚接触MVC、EF的概念,不知道如何操作。查阅了大量资料后发现,网上大部分类似内容都是基于mvc3的,最后还是在stackoverflow上找到一篇(中英文附后)。
&&&&&&& 但是一步一步按图索骥做下来,在AspNetUsers表中就是加不上Test列,其中还遇到一些错误,例如:几个地方显示使用的方法错误。
&&&&&&& 最后发现,该例子是基于asp.net 5/6的,许多需要添加的内容模板中已经有了,考虑是不是asp.net core有一些变化。
&&&&&&& 于是,直接将Test属性直接添加到ApplicationUser中去,发现问题解决了。
&&&&&&& 原来与之前考虑的一样,asp.net core已经将所需的所有内容都已经考虑好了,不需要做其他的修改。还有,这个版本与之前5/6版本几个方法发生了变化,所以出现了找不到方法的错误(已经标注到附录例子中了)。
我的具体代码如下:(Models/ApplicationUser.cs)
using System.Collections.G
using System.L
using System.Threading.T
using Microsoft.AspNetCore.Identity.EntityFrameworkC
namespace Test.Models
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
public string Test { get; set; }//之前该行是空白
&附:stackoverflow的例子&
I have made a sample web app named ShoppingList using the asp.net 5 web application template (Mvc6/MVC core/Asp.net-5). I wanted to extend the user profile with a custom field name DefaultListId.
我做了一个简单的网页应用,该应用使用asp.net 5 网络应用模板(Mvc6/MVC Core/Asp.net 5)。我想扩展用户配置文件,增加客户名称字段(DefaultListID)。
The ApplicationUser.cs:
namespace ShoppingList.Models
// Add profile data for application users by adding properties to the ApplicationUser class
public class ApplicationUser : IdentityUser
public int DefaultListId { get; set; }
In the home controller I would like to access the data stored for this property. I tried:
&在home控制器中,我想使用该属性,我做了如下尝试:
namespace ShoppingList.Controllers
public class HomeController : Controller
private UserManager&ApplicationUser& userManager = new UserManager&ApplicationUser&(new UserStore&ApplicationUser&(new ApplicationDbContext()));
public IActionResult Index()
var userId = User.GetUserId();
ApplicationUser user = userManager.FindById(userId);
ViewBag.UserId = userId;
ViewBag.DefaultListId = user.DefaultListId;
return View();
//other actions omitted for brevity
However I get the following errors:
但是,我得到错误信息如下:
Severity Code Description Project File Line Suppression State Error CS7036 There is no argument given that corresponds to the required formal parameter ‘optionsAccessor‘ of ‘UserManager.UserManager(IUserStore, IOptions, IPasswordHasher, IEnumerable&, IEnumerable&, ILookupNormalizer, IdentityErrorDescriber, IServiceProvider, ILogger&, IHttpContextAccessor)‘ ShoppingList.DNX 4.5.1, ShoppingList.DNX Core 5.0 C:\Users\OleKristian\Documents\Programmering\ShoppingList\src\ShoppingList\Controllers\HomeController.cs 15 Active
Severity Code Description Project File Line Suppression State Error CS1061 ‘UserManager‘ does not contain a definition for ‘FindById‘ and no extension method ‘FindById‘ accepting a first argument of type ‘UserManager‘ could be found (are you missing a using directive or an assembly reference?) ShoppingList.DNX 4.5.1, ShoppingList.DNX Core 5.0 C:\Users\OleKristian\Documents\Programmering\ShoppingList\src\ShoppingList\Controllers\HomeController.cs 20 Active
However, in order to do that, you first need to set up ASP.NET Identity to actually know about your ApplicationUser and make it be used for storing your user identities. To do that, you need to modify the Startup class. In the ConfigureServices method, you need to change the AddIdentity call to make it reference your actual types:
但为实现这个目的,你首先需要设置ASP.NET Identity,要其知道你的ApplicationUser,再让其可储存你的用户认可信息。要做到这一点,需要修改Startup类。在ConfigureServices方法中,需要修改AddIdentity,以便让它引用所需的实际类型。
services.AddIdentity&ApplicationUser, IdentityRole&()
.AddEntityFrameworkStores&ApplicationDbContext&()
.AddDefaultTokenProviders();
IdentityRole here refers to the standard role type used by ASP.NET Identity (since you don&t need a custom one). As you can see, we also reference a ApplicationDbContext there which is the entity framework database context for your mod so we need to set up that one too. In your case, it could just look like this:
这里的IdentityRole指的是ASP.NET Identity使用的标准角色类型(因此你不需要进行自定义)。正如你看到的,我们在这里也引用了ApplicationDbContext,它是为你修改过的identity model而准备的数据库上下文;所以我们也需要进行设置。在你当前的情况下,看起来如下所示:
public class ApplicationDbContext : IdentityDbContext&ApplicationUser&
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(builder);
// here you could adjust the mapping
This will make sure that the ApplicationUser entity is actually stored properly in the database. We&re almost done, but we now just need to tell Entity Framework about this database context as well. So again in the ConfigureServices method of your Startup class, make sure to adjust the AddEntityFramework call to also set up the ApplicationDbContext database context. If you have other database contexts, you can just chain these:
这将确保ApplicationUser实体妥善保存在数据库中。我们几乎完成了,但是现在我们也只需要告诉EF这个数据库的上下文。所以再次在Startup类的Configureservices方法中,确保调整AddEntityFramework也设置了Applicationdbcontext数据库上下文。如果你有其他数据库上下文,你可以反复这样做:
services.AddEntityFramework()//在Asp.Net Core中到不到这个方法,但是可以找到AddEntityFrameWorkAddSqlServer()方法,可能新版本将第一行和第二行的方法合并了
.AddSqlServer()
.AddDbContext&IdentityContext&(opts =& opts.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext&DataContext&(opts =& opts.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));//也找不到DataContext类
And that&s it! Now Entity Framework knows about the new user entity and properly maps it to the database (including your new property), and ASP.NET Identity also knows about your user model and will use that one for everything it does, and you can have the UserManager injected into controllers (or services, or whatever) to do stuff.
这样,EF就知道了新user实体及其映射到数据库的属性(包括你自定义的新属性);并且ASP.NET也知道了你自定义的user model,并据其做后面所有的事情;你也可将UserManager注入到控制器中(或者服务或其他所有事情)来处理事务了。
You should not instantiate your own UserManager, like ever. And it&s actually pretty hard to do so, since it requires you to pass in a lot of arguments to the constructor (and most of those things are also very difficult to set up properly).
不应该再像以前那样实例化UserManager,并且实际上那样做相当困难,因为这样做需要给构造器传递许多参数(并且许多配置要设置恰当是非常困难的)。
ASP.NET Core makes extensive use of dependency injection, so you should just set up your controller in a way that it receives the user manager automatically. That way, you don&t have to worry about creating the user manager:
ASP.NET Core广泛应用了注入技术,所以你应该仅给控制器设置为自动接收user manager。这样做,你就不必考虑创建user manager了。
public class HomeController : Controller
private readonly UserManager&ApplicationUser& userM
public HomeController (UserManager&ApplicationUser& userManager)
this.userManager = userM
However, in order to do that, you first need to set up ASP.NET Identity to actually know about your ApplicationUser and make it be used for storing your user identities. To do that, you need to modify the Startup class. In the ConfigureServices method, you need to change the AddIdentity call to make it reference your actual types:
然而,为了这样做,你首先需要设置ASP.NET Identity,让它知道你的ApplicationUser,并且让他用于存储你的用户身份认证信息。为了实现这个目的,你需要修改Startup类。在ConfigureServices方法中,你需要修改AddIdentity,让它引用你以及的类型:
services.AddIdentity&ApplicationUser, IdentityRole&()
.AddEntityFrameworkStores&ApplicationDbContext&()
.AddDefaultTokenProviders();
IdentityRole here refers to the standard role type used by ASP.NET Identity (since you don&t need a custom one). As you can see, we also reference a ApplicationDbContext there which is the entity framework database context for your mod so we need to set up that one too. In your case, it could just look like this:
这里的IdentityRole指的是ASP.NET Identity标准的角色类型(因为你不需要自定义的角色类型)。这里,我们也引用了ApplicationDbContext,这是用于你修改过的identity模型的数据库上下文;所以,我们也需要做如此设置。针对你的情况,应该是这样:
public class ApplicationDbContext : IdentityDbContext&ApplicationUser&
protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(builder);
// here you could adjust the mapping
This will make sure that the ApplicationUser entity is actually stored properly in the database. We&re almost done, but we now just need to tell Entity Framework about this database context as well. So again in the ConfigureServices method of your Startup class, make sure to adjust the AddEntityFramework call to also set up the ApplicationDbContext database context. If you have other database contexts, you can just chain these:
这将确保ApplicationUser实体被适当的储存到数据库中。我们几乎完成了,但现在我们仅需要告诉EF这个数据库上下文。所以再一次在Startup类的ConfigureServices方法中,确保调整AddEntityFrameWork,设置为ApplicationDbContext。如果你还有另外的数据库上下文,你可以反复这样做:
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext&IdentityContext&(opts =& opts.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext&DataContext&(opts =& opts.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
And that&s it! Now Entity Framework knows about the new user entity and properly maps it to the database (including your new property), and ASP.NET Identity also knows about your user model and will use that one for everything it does, and you can have the UserManager injected into controllers (or services, or whatever) to do stuff.
这样就完成了。现在EF就知道了新的user实体及其映射到数据库的属性(包含你设置的新属性);同时ASP.NET Identity也知道了你的user模型,接着就会按照该模型做他该做的事情了,这样你就能将UserManager注入到控制器中工作了。
As for your second error, you get this because the user manager does not have a FindById it only as a FindByIdAsync method. You will see this actually in a lot of places with ASP.NET Core that there are only asynchronous methods, so embrace it and start making your method asynchronous as well.
关于第二个错误,原因是user manager没有FindById方法,而是仅仅有FindByIdAsync方法。你将在很多使用ASP.NET Core的地方看到,仅有异步方法,所以拥抱并开始使用异步方法吧。
In your case, you would need to change the Index method like this:
在你的情况下,你需要像这样变更Index方法:
// method is async and returns a Task
public async Task&IActionResult& Index()
var userId = User.GetUserId();
// call `FindByIdAsync` and await the result
ApplicationUser user = await userManager.FindByIdAsync(userId);
ViewBag.UserId = userId;
ViewBag.DefaultListId = user.DefaultListId;
return View();
As you can see, it does not require many changes to make the method asynchronous. Most of it stays just the same.
正如你看到的,使用异步方法不需要太多的变化,很多都是一样的。
&&国之画&&&& &&
版权所有 京ICP备号-2
迷上了代码!3222人阅读
.net(31)
1.获取所有数据库名:
&& (1)、Select Name FROM Master.dbo.SysDatabases orDER BY Name
2.获取所有表名:
&& (1)、Select Name FROM SysObjects Where XType='U' orDER BY Name
&&&&&&&&&& XType='U':表示所有用户表;
&&&&&&&&&& XType='S':表示所有系统表;
&& (2)、SELECT name FROM sysobjects WHERE type = 'U' AND sysstat = '83'
&&&&&&&&&& 注意:一般情况只需要type = 'U',但有时候会有系统表混在其中(不知道什么原因),加上后面一句后就能删除这些系统表了
3.获取所有字段名:
(1)、Select Name FROM SysColumns Where id=Object_Id('TableName')
(2)、SELECT syscolumns.name,systypes.name,syscolumns.isnullable,syscolumns.length FROM syscolumns, systypes WHERE syscolumns.xusertype = systypes.xusertype AND &syscolumns.id = object_id('tableName')
&&&&&& 注意点:
&&&& (a)这里为了重点突出某些重要内容,选取了其中几项信息输出。
&&&& (b)syscolumns表中只含有数据类型编号,要获取完整的名字需要从systypes表中找,一般用户使用的数据类型用xusertype对应比较好,不会出现一对多的情况。
&&&& (c)syscolumns.length得到的是物理内存的长度,所以nvarchar和varchar等类型在数据库中的显示是这个的一半。
4、得到表中主键所包含的列名:
SELECT syscolumns.name FROM syscolumns,sysobjects,sysindexes,sysindexkeys WHERE syscolumns.id = object_id('tablename') AND sysobjects.xtype = 'PK' AND sysobjects.parent_obj = syscolumns.id AND sysindexes.id = syscolumns.id AND sysobjects.name = sysindexes.name
AND sysindexkeys.id = syscolumns.id AND sysindexkeys.indid = sysindexes.indid AND syscolumns.colid = sysindexkeys.colid
注意:这是在4张系统表中寻找的,关系比较复杂,大致可以表示为:
syscolumns中存有表中的列信息和表id,sysobjects表中存有主键名字(即PK_Table类似)和表id,sysindexes中存有主键名字和表id和index编号,sysindexkeys中存有表id和index编号和列编号,一项一项对应起来后就能找到列名了,呼~
5、得到表中列的描述内容:
select a.name,g.value from syscolumns as a&&& left join sysproperties g&& on a.id=g.id AND a.colid = g.smallid&&& where a.id='表id'
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:123250次
积分:1425
积分:1425
排名:千里之外
原创:13篇
转载:83篇
(3)(2)(3)(1)(2)(1)(7)(4)(3)(1)(1)(2)(2)(2)(8)(2)(5)(10)(4)(4)(3)(1)(1)(2)(1)(3)(2)(4)(2)(10)}

我要回帖

更多关于 asp.net 多选下拉列表 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信