【问题标题】:Display Data based on User selection from Dropdown menu根据下拉菜单中的用户选择显示数据
【发布时间】:2013-07-08 12:48:48
【问题描述】:

我正在创建一个页面。

我已使用 EF 为我的表创建类。

表架构如下:

AssetCategory has N TO M relationship with the other two tables 

在我的 aspx 页面中,我添加了一个下拉框并使用 EF 从 AssetCAtegaories 填充下拉列表,并从 Field Name 填充所有项目。

我添加了一个网格视图并将其绑定到显示 Jcode 的 AssetCategoryCodes。

现在我需要在这两个项目之间建立联系。

意思是根据用户从下拉列表中的选择在我的网格视图中显示项目。

编辑

MobileAssetCategoryID is Fk in AssetCategoyCodes
MobileAssetCategoryID  is FK in DowntimeReasonCodes

for Instance  in AssetCategories
 if ListItemID =1  and name = Honda 

if ListItemID =2  and name = Toyota


than AsstCategoryCodes   has 

MobileAssetCategory Id=1 , jCode =Accord


MobileAssetCategory Id=1 , jCode =Civic

MobileAssetCategory Id=2 , jCode =Camry

MobileAssetCategory Id=2 , jCode =corolla

所以我的问题是当用户在下拉列表中选择本田时?

我只想展示本田汽车,而不是所有东西。

我该怎么做?

【问题讨论】:

  • AssetCategoryCodes 中的哪个字段链接到 AssetCategories 中的哪个字段?字段名称看起来真的很混乱 - 关系似乎不是很明显......
  • 编辑解释表之间的关系

标签: asp.net entity-framework gridview


【解决方案1】:

解决了!它...这是我的 main.aspx.cs 中的代码

namespace Test
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        EntitiesName DbEntity = new EntitiesName();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var name = from c in DbEntity.MobileAssetCategories select new { c.ListItemId, c.Name };
            MainCodes.DataSource= name.ToList();
            MainCodes.DataValueField = "ListItemId";
                MainCodes.DataTextField= "Name";
                MainCodes.DataBind();
                MainCodes.Items.Insert(0,"--Select--");

            }

        }

        protected void MainCodes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int JCodeId = Convert.ToInt32(MainCodes.SelectedValue.ToString());
            var JCode = from c in DbEntity.MobileAssetCategoryCodes where c.MobileAssetCategoryId.Equals(JCodeId) select new { c.JdeCode };
            JCodeDisplay.DataSource = JCode.ToList();
            JCodeDisplay.DataBind();
            int reasonCode = JCodeId;
            var RCode = from a in DbEntity.MobileAssetDowntimeReasonCodes where a.MobileAssetCategoryId.Equals(reasonCode) select new { a.JdeReasonCode };
            ReasonCode.DataSource = RCode.ToList();
            ReasonCode.DataBind();

        }

        protected void JCodeDisplay_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void ReasonCode_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2014-10-04
    • 1970-01-01
    相关资源
    最近更新 更多