DataBound DetailsView中的DropDownList [英] DropDownList in DataBound DetailsView

查看:63
本文介绍了DataBound DetailsView中的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以数据绑定到Customer数据实体对象的详细信息视图。客户通过外键连接到Company对象。我需要使用公司列表填充下拉列表,并使所选项目与该客户相关联。我不太清楚如何解决这个问题。

I have a detailsview that is databound to a Customer data entity object. The customer is connected to a Company object via a foreign key. I need to populate a dropdownlist with a list of Companies, and have the selected item be the one that is connected with that customer. I''m not too sure how to go about this.

推荐答案

我将通过数据结构向您解释逻辑。假设:数据模型(如同在DB中一样呈现)将类似

I will explain you the logic via data-structure. Assumption: Data model (presenting as if in DB) would be something like
CustomersTable
CustomerID CustomerName CompanyID

CompanyTable
CompanyID CompanyName







现在,要获得给定客户的数据,SQL查询将是喜欢:




Now, to have data for a given customer, a SQL query would be like:

SELECT 
   CompanyName, CompanyID 
FROM 
   CompanyTable 
INNER JOIN 
   CustomerTable ON CompanyTable.CompanyID = CustomerTable.CompanyID 
WHERE   
   CustomerTable.CustomerID = @customerid



因此,您获得与给定客户关联的客户端,您可以使用并设置该公司下拉。



根据以上逻辑尝试。


Thus, you get the client associated with the given Customer which you can use and set the company dropdown with.

Try out based on above logic.


这篇关于DataBound DetailsView中的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆