GridView 中的 DropDownList 选择 GridView BoundField
在 ASP.NET 4 中,我有一个 GridView,它在 asp:TemplateEdit 部分中包含一个 DropDownList。 DropDownList 填充了我需要从第二个数据源获取的所有选项。但是,我希望每行中的每个 DropDownList 根据 GridView 中已有的数据默认设置不同的 SelectedIndex。
例如,这里是示例数据
| id | Status | hidden | First Name |
--------------------------------------------------
| 12 | <dropdown> | 3 | john doe |
| 13 | <dropdown> | 7 | jane ble |
,因此您会注意到第三列是隐藏的,这意味着我将其设置为:
<asp:BoundField DataField="StatusName" HeaderText="Status" Visible="false" />
但是,此列中编辑的行包含我需要 DropDownList 默认显示的值 (asp:BoundField)。
换句话说,我需要
<option select="selected">something</option>
根据“隐藏”字段中的数字选择正确的索引。
In ASP.NET 4, I have a GridView, which contains a DropDownList in the asp:TemplateEdit section. The DropDownList is populating with all of the options I need from a second data source. However, I would like to have each DropDownList in each row have a different SelectedIndex set on default based on data already in the GridView.
For example, here is sample data
| id | Status | hidden | First Name |
--------------------------------------------------
| 12 | <dropdown> | 3 | john doe |
| 13 | <dropdown> | 7 | jane ble |
so you will note the 3rd column is hidden, meaning I have it set to:
<asp:BoundField DataField="StatusName" HeaderText="Status" Visible="false" />
However, the edited row in this column contains the value (asp:BoundField) that I need the DropDownList to display by default.
In other words I need
<option select="selected">something</option>
to have the proper index selected based on the number in the "hidden" field.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以订阅
RowDataBound
事件,以便在下拉列表中选择正确的值:You can subscribe to
RowDataBound
event in order to select the right value in the drop-down list: