[英]Asp.Net Dropdown onchange Event Not Working
In my company want to modify one ASp.net Project, 我公司要修改一个ASp.net项目,
<asp:DropDownList ID="drdIssuer" runat="server" CssClass="txtfield" AutoPostBack="True" OnSelectedIndexChanged="drdIssuer_SelectedIndexChanged" onchange="showvalues();">
<asp:ListItem>Val1</asp:ListItem>
<asp:ListItem>Val1</asp:ListItem>
<asp:ListItem>Val1</asp:ListItem>
<asp:ListItem>Val1</asp:ListItem>
</asp:DropDownList>
This is html asp code,And JAvascript like this, 这是html asp代码,以及类似Java的脚本,
<script type="text/javascript">
function showvalues()
{
alert('Yes');
}
</script>
When I change dropdown listing I want to work showvalues() function how do i do it,Can you guys help me.... 当我更改下拉列表时,我想使用showvalues()函数,该怎么做,你们能帮我吗?...
您可以为由asp:dropdown呈现的select元素注册一个html事件。
drdIssuer.Attributes["onchange"] = "showvalues();";
1.You are getting that error because, you have might not added the namespace 1.您收到该错误,因为您可能未添加名称空间
using System.Data.SqlClient;
I got the error Server Error in '/' Application 我在“ /”应用程序中收到错误服务器错误
For that you may go for a detailed solution mentioned at Geeks blogs . 为此,您可以寻求Geeks博客中提到的详细解决方案。
And also have a look at here As, it is not a major issue and as per the information provided by you, the above solution should work. 另外,在这里也可以看到,因为这不是主要问题,根据您提供的信息,上述解决方案应该可以使用。
Your whole code-behind for the drdIssuer_SelectedIndexChanged
should look like this 您的drdIssuer_SelectedIndexChanged
整个代码应如下所示
using System.Data.SqlClient; //namespace
protected void drdIssuer_SelectedIndexChanged(object sender, EventArgs e)
{
SqlParameter[] param = new SqlParameter[1];
if (drdIssuer.SelectedValue == "Val1")
{
Response.Write(@"<script langauge='text/javascript'>alert('...Alert Goes here...');</script>");
}
}
Also if you remove the onChange
function from the values. 同样,如果您从值中删除onChange
函数。 Your Response.Write
will also work for Val1
您的Response.Write
也将适用于Val1
<asp:DropDownList ID="drdIssuer" runat="server" OnSelectedIndexChanged="drdIssuer_SelectedIndexChanged"
CssClass="txtfield" AutoPostBack="True">
<asp:ListItem>Val1</asp:ListItem>
<asp:ListItem>Val2</asp:ListItem>
<asp:ListItem>Val3</asp:ListItem>
<asp:ListItem>Val4</asp:ListItem>
</asp:DropDownList>
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.