2012-06-18 24 views

回答

1

您可以在下拉菜單中添加onchange事件,如果你不需要從數據庫/服務器端

<ItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" onchange="BindEng(this);" Height="16px" Width="179px"> <ItemTemplate> 

任何添加的RowDataBound事件GridView和每一行訪問下拉菜單,並分配javascript來了,在這裏你可以訪問數據源的數據,如果JavaScript功能需要。

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 + "'"); 
    } 
} 
+0

嗨@Adil感謝解決[添加JavaScript到ASP.NET下拉列表(模板歸檔)Gridview?]。這工作。 – Uneverno

+0

不客氣,我現在會回答第二部分 – Adil

+0

我們也可以在控件的源代碼級別定義它,如下所示。 Uneverno

0

要添加javacript到下拉,並通過所選擇的值 - > ddl.Attributes.Add( 「平變化」, 「BindEng( ' 」+ ddl.SelectedValue +「');」);

相關問題