GridView 的 asp:HiddenField 的等效项
没有可以在 GridView 中使用的 asp:HiddenField 所以我想知道什么可以与此类似。
我想要这个的原因是我有一个触发 OnRowCommand 的 ButtonField。 从那里我可以找出选择了哪一行,但我无法从 ButtonField 检索文本值以查看绑定到它的数据(通过 DataTextField)。
我的解决方案是使用 BoundField 并从中检索文本值,因为我已经知道选择了哪一行。 这有效,但我需要将其隐藏。
有人建议使用嵌套在 TemplateField 中的 HiddenField,但我在从该 HiddenField 检索文本值时遇到了麻烦。 有没有某种方法可以访问 TemplateField 中的控件以获取 HiddenField 的文本值?
如果有人对替代方案有任何建议,那就太好了。
谢谢,
马特
There is no asp:HiddenField that can be used in a GridView so I was wondering what would work similar to this.
My reasoning for wanting this is I have a ButtonField that triggers an OnRowCommand. From there I can figure out which row was selected, but I cannot retrieve the text value from the ButtonField to see the data that was bound to it (through DataTextField).
My solution to this was to have a BoundField and just retrieve the text value from it instead, since I already knew which row was selected. This worked, but I need it to be hidden.
Someone suggested using a HiddenField nested within a TemplateField, but I had troubles retrieving the text value from that HiddenField. Is there some way to access the control within the TemplateField to get the text value of the HiddenField?
If anyone has any suggestions for alternatives that would be great as well.
Thanks,
Matt
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是否可以添加另一个 ID 列,作为记录(行)的唯一代表? 可以使用 style: display=none 设置该特定 ID 列以隐藏它,但 ID 仍然位于 HTML 表单内。
然后您可以检索该特定 ID 列的值以进行进一步处理。
希望这有帮助,
哈迪
is it possible to add another ID column, as a unique representative for a record(row) ? That particular ID column can be set with style: display=none in order to hide it, but still the ID is inside the HTML form.
and then you can retrieve the value of that particular ID column to be processed further.
hope this helps,
hadi
您可以使用模板字段,其 commandArgument 等于记录/行的 ID。
然后,在行命令处理事件中,您可以通过 e.CommandArgument 获取该值
You can use a template field with the commandArgument equal to the the ID of the record/row.
Then, in the row command handling event you can get that value by e.CommandArgument
您可以使用DataKeyNames Gridview 上的属性。
然后你可以像这样访问它们:
You can use the DataKeyNames property on the Gridview.
and then you can access them like this: