如何从 GridView 获取选定值 (C#)
我有 GridView 允许选择。它从 EntityDataSource 获取数据。如何获取选择 GridView 中的行时选择的实体对象? 实体的主键不会显示在 GridView 中。
感谢您的解答
I have GridView
that allows select. It takes data from EntityDataSource
. How do I get the entity Object that is selected when the row in GridView
is selected ?
Primary keys of entities are not displayed in the GridView
.
Thanks for answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在 gridview 中使用模板字段,则可以在选择命令的 CommandArgument 属性中传递主键。示例:
然后,当用户单击“选择”按钮时,会在 gridview 上触发“RowCommand”事件。如果您捕获此事件并检查 e.CommandArgument 属性,您将能够访问与他们选择的行相对应的主键:
希望这有帮助!
If you're using a template field in your gridview, you can pass the primary key in the CommandArgument property for your select command. Example:
Then, when the user clicks the "select" button, this triggers a "RowCommand" event on your gridview. If you capture this event and check the e.CommandArgument property, you'll be able to gain access to the primary key corresponding to the row they selected:
Hope this helps!
您可以使用网格视图的 DataKeyNames 字段属性,也可以放置隐藏值并将数据绑定到数据绑定事件。使用隐藏字段 Gridview 选择事件,您可以搜索找到隐藏字段并从那里获取值。谢谢
以下链接将为您提供帮助。
http://forums.asp.net/t/951615.aspx
You can either use the DataKeyNames field property of a grid view or you can also put the hidden value and bind the data on data bound event. Using hidden field Gridview selected event you search find hidden filed and get the value from there. Thanks
Following link will help you.
http://forums.asp.net/t/951615.aspx
您可以使用网格视图中的隐藏控件来隐藏主键
you can use hidden control in the gridview to hidden the Primary keys
你可以使用主键去数据库搜索带有主键的记录。所以然后在程序中使用一个类来接收数据。(c#是属性)
you can use primary key goto the database search the record with the primary key .so then in the program use a class to receive the data.(c# is property)