如何检索业务实体中的其他值
该方法的返回类型为集合<businessEntity>。我从 aspx 页面调用该方法以填充下拉菜单 -> ddlDropDown。我将 ddlDropDown 的 DataTextField 与 BusinessEntity.Name 绑定,将 DataValueField 与 BusinessEntity 绑定。 Id,业务实体包含另一个id,即BusinessEntity.ProductId。我需要使用后面代码中下拉列表中所选值的 ProductId 。你能帮我建议一下我该怎么做吗?
一种可能的方法是在后面的代码中调用 page_Load 中的方法,并将集合保存在隐藏变量中,并在需要时在隐藏变量中循环并检索所选值产品 ID。
请你的想法。
The method has a return type of collection<businessEntity>. I am calling the method from the aspx page in order to populate a drop down -> ddlDropDown. I am binding he DataTextField of the ddlDropDown with the BusinessEntity.Name and the DataValueField with BusinessEntity.Id, the business entity contains another id which is BusinessEntity.ProductId. I need to use the ProductId of the value selected in the drop down list in the code behind. Can you help suggest how I can do so?
One possible way could be to call the method in the page_Load on the code behind and save the collection in a hidden variable and when required do a loop through in the hidden variable and retrieve the selected value Product Id.
Your thoughts please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当然可以使用隐藏字段来完成此操作。
这是另一个想法:将 DataValueField 绑定到一个特殊的派生字符串,其中包含 BusinessEntity.Id 和 BusinessEntity.ProductId。
换句话说,将 BusinessEntity.Id 和 BusinessEntity.ProductId 连接成单个字符串,例如用竖线(“|”)符号分隔。
例如绑定:
然后检索所选项目:
节省循环/匹配。同样,它并不理想,但同样,将多个值类型绑定到下拉列表也不是。
You could certainly accomplish this using a hidden field.
Here's another idea: bind the DataValueField to a special derived string, containing the BusinessEntity.Id AND the BusinessEntity.ProductId.
In other words, concatenate the BusinessEntity.Id and BusinessEntity.ProductId into a single string, seperated by the pipe ("|") symbol for example.
E.g to bind:
Then to retrieve selected item:
Saves you looping/matching. Again, its not ideal, but then again neither is binding multiple values types to a dropdownlist.