如何将JavaScript添加到Gridview的ASP.NET Dropdownlist(模板文件)中?
如何在ASP.NET Dropdownlist上添加JavaScript,将该Dropdownlist Id传递给调用的同一JavaScript函数。如何对Dropdownlist(Gridview的模板字段)执行相同操作。如果不需要数据库/服务器端的任何内容,可以在Dropdownlist中添加onchange事件如何将JavaScript添加到Gridview的ASP.NET Dropdownlist(模板文件)中?,javascript,asp.net,javascript-events,Javascript,Asp.net,Javascript Events,如何在ASP.NET Dropdownlist上添加JavaScript,将该Dropdownlist Id传递给调用的同一JavaScript函数。如何对Dropdownlist(Gridview的模板字段)执行相同操作。如果不需要数据库/服务器端的任何内容,可以在Dropdownlist中添加onchange事件 <ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" onchange="Bind
<ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" onchange="BindEng(this);" Height="16px" Width="179px"> <ItemTemplate>
要将JavaScript添加到下拉列表并传递所选值-->
Add(“onchange”、“BindEng(“+ddl.SelectedValue+”);” Hi@Adil感谢您为[将JavaScript添加到Gridview的ASP.NET Dropdownlist(模板文件)?]提供的解决方案。我们还可以在控件的源代码级别定义它,如下所示。谢谢,是的,如果我们只需要通过宾登考试就更好了。当我们必须传递某个变量时,答案中的代码很有用。我会更新我的答案。
protected void GrdViewUsers_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = e.Row.FindControl("YourDropDownListID") as DropDownList;
//The statment below will pass the client id of drop down to function in javascript
ddl.Attributes.Add("onchange", "YourjavascriptMethodCall('" + ddl.ClientID + "'");
}
}