c# - Eval()、XPath() 和 Bind() 等数据绑定方法只能在 Gridview 中的数据绑定控件的上下文中使用
问题描述
我正在尝试构建一个包含几列的gridview。但是我遇到了这个错误“Eval()、XPath() 和 Bind() 等数据绑定方法只能在数据绑定控件的上下文中使用。”
我不确定为什么会这样。我尝试将 Eval("pid") 的语法更改为 (DataBinder.Eval(Container.DataItem,"pid")) 但无济于事。我可能会错过什么?这是我在其他几列中的一列的 aspx 代码。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
ShowFooter="false" ShowHeaderWhenEmpty="true"
DataKeyNames="pid"
OnRowCommand="GridView1_RowCommand"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowUpdating="GridView1_RowUpdating"
AllowPaging="True" PageSize="30"
Width="100%" AllowSorting="True"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Project Number" ItemStyle-HorizontalAlign="center">
<ItemTemplate>
<asp:Label ID="lblPID" Text='<%# Eval("pid") %>' Width="130px" runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtProjectNumber" Text='<%# Eval("pid") %>' ToolTip='<%# Eval("pid") %>' Width="130px" runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
任何帮助都非常感谢,因为我长期以来一直被困在这个问题上。提前致谢。
解决方案
推荐阅读
- javascript - 为什么我的时间在提交时没有显示正确的输出?
- database - 我的程序依靠哈希来识别文件,有些是重复的。我该如何解决这个问题?
- r - 重新安装R后,我得到错误信息来一个一个重新安装一堆包
- xss - next.js 应用如何防止 XSS 和 CSRF 攻击?
- java - 如何在ascii中输入并以字符串形式打印?
- python - 如何将 for 循环的结果存储到给定特定列/行的数据帧?
- javascript - 如果我在网络浏览器中点击返回按钮,重定向页面?
- python - 我面临语音识别中的错误
- r - 匹配字符串正则表达式完全匹配
- flutter - Flutter中最小化SliverAppBar时有没有办法看到内容?