当前位置:编程学习 > C#/ASP.NET >>

C# 中用JS脚本为DropDownList控件值

页面有一DropDownList控件:
<asp:DropDownList ID="ParentID" runat="server">
    <asp:ListItem Value="0">-=新建一级菜单=-</asp:ListItem>
    <asp:ListItem><=请点击右边菜单,选取菜单</asp:ListItem>
</asp:DropDownList>

别外有一js脚本:
<script language="JavaScript">
function m_Click(MenuId,MenuName)
{
m_objSelect=document.body.all("ParentID");
if(m_objSelect.style.display=="")
{
m_objSelect.options[1].text=MenuName;
m_objSelect.options[1].value=MenuId;
m_objSelect.selectedIndex=1;
}
}
</script>
脚本主要是用来改变DropDownList第二项的值
用ParentID.SelectedItem.Value来接收
但是在接收DropDownList传来的值时还是第一项的,在ASP中可用.
--------------------编程问答-------------------- ParentID.SelectedItem.Value不对

var strValue=document.getElementById(strDropDownListCWDM).options[document.getElementById(strDropDownListCWDM).selectedIndex].value --------------------编程问答-------------------- var strValue=document.getElementById(ParentID).options[document.getElementById(ParentID).selectedIndex].value
--------------------编程问答-------------------- var strValue=document.getElementById(ParentID).options[document.getElementById(ParentID).selectedIndex].value

这个正确 --------------------编程问答-------------------- 我是要在C# .cs文件中接收DropDownList传来的值.不是这个js脚本.
var strValue=document.getElementById(ParentID).options[document.getElementById(ParentID).selectedIndex].value --------------------编程问答-------------------- 我是要在C#  .cs文件中接收DropDownList传来的值.不是这个js脚本.  
var  strValue=document.getElementById(ParentID).options[document.getElementById(ParentID).selectedIndex].value 
而是C# 语法 --------------------编程问答-------------------- 客户端改变的值,服务器端是接受不到的,你可以考虑用js把这个改动的值放入到一个hidden中,在服务器端用Request.Form["hidden控件名"]来得到 --------------------编程问答-------------------- 但是控件textbox的可以啊,我用JS脚本来改变C#中textbox控件的值,服务端可以接收,用DropDownList就只用接收第一项的值,在页面js脚本可以改变DropDownList的Text值.但有服务端用ParentID.SelectedItem.Value来接收就还是第一项的值. --------------------编程问答-------------------- C#入门啊,有好多好多问题!.高手们加唵QQ:18638588 验证信息:csdn --------------------编程问答--------------------
在服务器端写不就赋值了吗.

DropDownList.SelectedItem.Value --------------------编程问答-------------------- m_objSelect=document.getElementById("ParentID"); --------------------编程问答-------------------- document.all("dropdownlist_aa").options.add(new Option(piArray[i].toString(),piArray[i].toString())); --------------------编程问答--------------------
在服务器端写不就赋值了吗.  
 
DropDownList.SelectedItem.Value 

可以传来的值还是第一项的
(<asp:ListItem  Value="0">-=新建一级菜单=-</asp:ListItem>)

不是要的第二项.在页面中js脚本已经改变了ListItem 
(<asp:ListItem><=请点击右边菜单,选取菜单</asp:ListItem> )
但提交服务端还是第一项. --------------------编程问答-------------------- <asp:DropDownList ID="ParentID" runat="server">
说明页面的DropDownList控件是服务器端运行的。

<script language="JavaScript">
是客户端的JS,他的值在服务器端是得不到的,甚至他都不能访问服务器端控件的。
也就是说m_objSelect=document.body.all("ParentID");根本就没得到服务器端的DropDownList控件

应该尝试着都在服务器端处理。或者使用Page.RegisterStartupScript(); --------------------编程问答-------------------- dropdownlist没有文本输入框框的,我想用层做一个输入框框,我的dropdownlist是动态生成的,这个时候我就要将层移动到dropdownlist上去。请问我怎么获取dropdownlist的坐标值,然后让层覆盖该dropdownlist?


以下帖子给分。
如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
http://community.csdn.net/Expert/topic/5481/5481151.xml?temp=.4136316
--------------------编程问答-------------------- dropdownlist没有文本输入框框的,我想用层做一个输入框框,我的dropdownlist是动态生成的,这个时候我就要将层移动到dropdownlist上去。请问我怎么获取dropdownlist的坐标值,然后让层覆盖该dropdownlist?


以下帖子给分。
如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
http://community.csdn.net/Expert/topic/5580/5580708.xml?temp=.7489435
昨天晚上发错连接,更正在发送。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,