如何根据来自代码隐藏或 DataGrid 中数据源的数据更改项目模板中的组合框
我有一个数据网格,数据来自数据库,它在状态中有组合框,我希望它们根据各自的值,例如,有一列状态,它有一个组合框:打开和关闭,我希望它相对于数据库表列中的值进行更改,如果数据库表列中写入了“关闭”,则组合框应选择为“关闭”,如果它具有“打开”,则应选择为“打开”。请参阅所附图片。 提前感谢您的帮助。
I have a data grid, and data is coming from database, it has combo boxes in status and I want them to be according to their respective values, for example, there is a column of status, it has a combo box: Open and Close, I want it to be changed with respect to the value it has in database table-column, if it has Close written in database table column, combo box should be selected as Close, if it has Open then it should be selected as Open. Please see the image attached.
Thanks for Help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您使用的是模板列,您可以这样做:
如果您想在
ItemDataBound
事件中设置 SelectedValue,您可以这样做:Assuming that you're using a template column, you can do this:
If you want to set the SelectedValue in the
ItemDataBound
event, you can do it like this:首先将数据源保存在视图状态中。如果数据源是数据表则这样做。
First of all save your data source in viewstate. If datasource is datatable then do like this.