简体   繁体   English

ASP.NET (C#) 中的 DetailView 在编辑模式下使用下拉列表将主键推送到数据库

[英]DetailView in ASP.NET (C#) in Edit Mode using DropDown list pushing Primary Key to Database

How to have primary key fields in Grid and Detail view but show the name field.如何在网格和详细信息视图中有主键字段但显示名称字段。 And then have drop downs in edit mode.然后在编辑模式下有下拉菜单。

I have a SQL database that I am connecting to my website through LINQ and using ASP.NET (C#).我有一个 SQL 数据库,我通过 LINQ 并使用 ASP.NET (C#) 连接到我的网站。

The database is a simple equipment inventory database that has four tables该数据库是一个简单的设备库存数据库,有四个表

  1. equipment description设备说明
  2. equipment manufacturer设备制造商
  3. location地点
  4. history of where the equipment is located设备所在位置的历史

The equipment description table has a data field for manufacturer which I populated with the primary key of the equipment manufacturer table.The history table has a data field for the equipment id (primary key) of the equipment description table and a data field for location id (primary key) from the location table.设备描述表有一个制造商数据字段,我用设备制造商表的主键填充。历史表有一个数据字段用于设备描述表的设备 ID(主键)和一个数据字段用于位置 ID (主键)来自位置表。

I can make the connection to the database and I am trying to use Gridviews and Detail Views.我可以连接到数据库,我正在尝试使用 Gridviews 和 Detail Views。

But when I display the equipment table with a grid view or an individual item in a detail view I see the manufacturer id and not the manufacturer name.但是,当我在详细视图中显示带有网格视图或单个项目的设备表时,我看到的是制造商 ID,而不是制造商名称。 I understand that is what I should see.我明白这是我应该看到的。 I can create a SQL view ( query) where I would have both the manufacturer id and the name and can then show the data field of the manufacturer name.我可以创建一个 SQL 视图(查询),其中我将同时拥有制造商 ID 和名称,然后可以显示制造商名称的数据字段。 But I know there is a way that I could do this without the query, and have some sort of way in the “Item Template” view to see the manufacturers name.但我知道有一种方法可以在没有查询的情况下执行此操作,并且在“项目模板”视图中有某种方法可以查看制造商名称。 And in the “Edit Template” view have a dropdown list that would pull from the manufacturers table that would show the manufacturers name but put the manufacturers id into the data field once one has “Updated” the data.在“编辑模板”视图中有一个下拉列表,该列表将从制造商表中拉出,显示制造商名称,但一旦“更新”数据,就会将制造商 ID 放入数据字段中。

I have tried looking up tutorials on the web but seem to not be looking up the right words.我试过在 web 上查找教程,但似乎没有找到正确的词。 I get stuck at getting tutorials just showing the dropdown list and not the step pushing the primary key back into the database.我被困在只显示下拉列表的教程上,而不是把主键推回数据库的步骤。 Or showing the manufactures name when initially displaying the table.或者在最初显示表格时显示制造商名称。 I figure if I can get this to work in the Detail view it will basically be the same type of process for Grid Views.我想如果我可以让它在细节视图中工作,它基本上是网格视图的相同类型的过程。 I am hoping the example does not go too deep into coding and works with the wizard-like tools I am using in Visual studio.我希望该示例不会对编码过于深入,并且可以与我在 Visual Studio 中使用的类似向导的工具一起使用。 I know asking a lot.我知道问了很多。

Hopefully someone can point me to the right video or text tutorial that I can make this work.希望有人能指出我可以完成这项工作的正确视频或文本教程。

It took enough tries that I finally found the resource I was look for and it seems to be working.经过足够多的尝试,我终于找到了我正在寻找的资源,而且它似乎正在工作。 I searched for "ASP.NET LINQ GridView DropDownList from secondary Table" and bingo.我从辅助表中搜索了“ASP.NET LINQ GridView DropDownList”和宾果游戏。

See Scotts Gu Blog for a LINQ step by step有关LINQ 的逐步说明,请参阅 Scotts Gu 博客

See jSCAP solution for SQLDataSource step by step 逐步查看 SQLDataSource 的 jSCAP 解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM