[英]Display Data based on User selection from Dropdown menu
我正在创建一个页面。
我已经使用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
所以我的问题是用户何时在下拉列表中选择本田?
我只想展示本田汽车,而不是所有东西。
我怎样才能做到这一点 ?
解决了! 它...这是我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)
{
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.