使用javascript更改Gridview中下拉列表的选定文本
我有一个下拉列表和一个网格视图,其中一列是下拉列表。
两个下拉列表使用相同的数据源。
当在下拉列表中(网格视图之外)选择一个值时,我想更改网格视图中每个下拉列表的 selectedValue 和 selectText 。
这是我尝试过的:
Dropdownlist:
<asp:DropDownList onclick="javascript:onJDSelection()" ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource4" DataTextField="circt_cstdn_nm"
DataValueField="circt_cstdn_user_id">
Javascript:
<script type="text/javascript">
function onJDSelection() {
var jd = document.getElementById('DropDownList3.ClientID').selectedText;
var grid = document.getElementById('GridView2.ClientID');
//Loop starts from 1 because the zeroth row is the header.
for (var i = 1; i < grid.rows.length; i++) {
var OtherText = grid.rows[i].cells[2].innerText; // Works fine
grid.rows[i].cells[3].getElementsById('ddl_JD').selectedText = jd;
}
}
当我点击时出现错误。它说预期的对象。但我知道那些物体存在!
有什么想法吗?谢谢!
I have a dropdownlist, and a Gridview where one of the columns is a dropdownlist.
both dropdown lists use the same data source.
When a value is selected in the dropdownlist (outside the gridview) I want to chaneg the selectedValue and selectText of every dropdownlist in my gridview.
This is what I have tried:
Dropdownlist:
<asp:DropDownList onclick="javascript:onJDSelection()" ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource4" DataTextField="circt_cstdn_nm"
DataValueField="circt_cstdn_user_id">
Javascript:
<script type="text/javascript">
function onJDSelection() {
var jd = document.getElementById('DropDownList3.ClientID').selectedText;
var grid = document.getElementById('GridView2.ClientID');
//Loop starts from 1 because the zeroth row is the header.
for (var i = 1; i < grid.rows.length; i++) {
var OtherText = grid.rows[i].cells[2].innerText; // Works fine
grid.rows[i].cells[3].getElementsById('ddl_JD').selectedText = jd;
}
}
When I click I get an error. It says object expected. However I know those objects exsist!
Any ideas? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 DOM 模型,而不是直接根据 ID 获取下拉列表(ASP.Net 更改你的“ddl_JD”)。您至少知道单元格(grid.rows[i].cells[3])。所以尝试 nextSibling ...
You could use the DOM model instead of getting the dropdownlist directly per ID(ASP.Net changes your 'ddl_JD'). You know at least the cell(grid.rows[i].cells[3]). So try nextSibling ...