我遇到了一些麻烦,经过相当多的研究,一直无法找到解决方案。我在SharePoint Designer 2010工作,有一个ASP.net下拉列表填充。我想从下拉列表中获得所选项目的索引值(例如1),并将其传递给用于调出EditForm的URL。aspx页面。见下文,感谢您提供的任何帮助!
<script type="text/javascript">
function redirect(url) {
var ddl = document.getElementById('DropDownList1');
alert("HI!");
var index = ddl.selectedIndex;
var value = ddl.options[index].value;
location.href = url + value;
return false;
}
</script>
<asp:LinkButton runat="server" id="LinkButton1"
href="https://chartiscorp.sp.ex3.secureserver.net/Lists/System_Information/EditForm.aspx?id="
onclientclick="javascript:redirect(this.href)">Edit System Info</asp:LinkButton>
<asp:DropDownList runat="server" id="DropDownList1" DataValueField="Title"
DataTextField="Title" DataSourceID="spdatasource1" />
您应该使用呈现的ID:
var ddl = document.getElementById('<%=DropDownList1.ClientID%>');
和LinkButton
的OnClientClick
事件:
<asp:LinkButton onclientclick="...">
使用
获取索引var index = ddl.selectedIndex;
或者如果你想获得值,使用
var value = ddl.options[ddl.selectedIndex].value;
我建议在函数中进行重定向,而不是在HTML属性中。集合:
<script type="text/javascript">
function redirect(url) {
var ddl = document.getElementById('<%=DropDownList1.ClientID%>'),
index = ddl.selectedIndex,
value = ddl.options[index].value;
location.href = url + value;
return false;
}
</script>
<asp:LinkButton runat="server" id="LinkButton1"
href="../Lists/System_Information/EditForm.aspx?id="
onclientclick="redirect(this.href)">LinkText</asp:LinkButton>
<asp:DropDownList runat="server" id="DropDownList1" DataValueField="Title"
DataTextField="Title" DataSourceID="spdatasource1" />