gpt4 book ai didi

asp.net - <%# 在 aspx 文件中是什么意思

转载 作者:行者123 更新时间:2023-12-04 16:11:15 25 4
gpt4 key购买 nike

以前没做过aspx。正在尝试修复错误。

我已经追踪到这行代码:

<asp:DropDownList ID="ddlProject_Edit" selectedvalue='<%# Bind("ProjectsId") %>' runat="server"  CssClass="ddl" DataSourceID="dsProject_Edit" DataTextField="DESCRIPTION" DataValueField="BOUND_"></asp:DropDownList>

我收到这个错误:

Error: Sys.WebForms.PageRequestManagerServerErrorException: 'ddlProject_Edit' has a SelectedValue which is invalid because it does not exist in the list of items.

所以我猜测它与 <%# Bind("ProjectsId") %> 有关一 block 。

什么是<%#做?在谷歌上搜索这些字符并没有被证明是很有成果的。

更有帮助的是关于 Bind("ProjectsId") 的解释正在做。

最佳答案

这是一个 Data Binding Expression .

据说这里有两组数据在起作用:

  • 用于填充 DropDownList 中选项的一组项目
  • 中继器/网格/等中的一组记录。某种包含 DropDownList

这段代码基本上是在说:

For the record that this "row" represents, set the value of this control to the ProjectsId value in that record.

至于错误,发生的事情是该记录的值不存在于 DropDownList 中。为了说明这一点,假设您有一个包含以下项目的 DropDownList:

  • 苹果
  • 橙色
  • 香蕉

这里发生的是记录的值为 "Pear"。因此系统无法在 DropDownList 中设置值,因为该值不存在。

这背后的根本问题是数据不好。数据中存在损坏的引用完整性。记录具有不存在的查找值。要么数据需要更正,要么应用程序不能再假设数据是正确的并且必须考虑到这一点。

关于asp.net - <%# 在 aspx 文件中是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36036934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com