Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从asp:DataGrid ItemCommand执行jQuery函数_Jquery_Asp.net - Fatal编程技术网

从asp:DataGrid ItemCommand执行jQuery函数

从asp:DataGrid ItemCommand执行jQuery函数,jquery,asp.net,Jquery,Asp.net,我有一个asp:DataGrid,在这个网格视图中有一个asp:ButtonColumn。当我单击delete action时,我在delete case开关中输入。如果结果为false,我希望执行.aspx页面中定义的jQuery函数 有可能这样做吗 <asp:DataGrid runat="server" ID="dgList" InItemCommand="dgList_ItemCommand"> <asp:ButtonColumn Text="Delete" C

我有一个asp:DataGrid,在这个网格视图中有一个asp:ButtonColumn。当我单击delete action时,我在delete case开关中输入。如果结果为false,我希望执行.aspx页面中定义的jQuery函数

有可能这样做吗

<asp:DataGrid runat="server" ID="dgList" InItemCommand="dgList_ItemCommand">
    <asp:ButtonColumn Text="Delete" CommandName="delete" />
</asp:DataGrid>

单击按钮时,最好从客户端开始,使用ajax请求调用服务器端逻辑。这样,您可以选择是否在客户端继续


您可以将删除代码移动到一个位置,并在单击按钮时从jQuery调用它。

您可以随时执行类似的操作,但这有点突兀

根据您的结果将myResult设置为公共bool

在代码隐藏中:

case "delete":
            myResult = new MyClass().GetTest();
            break;
}
加:

In.aspx

<% if (myResult)
  { %>
    //Do Jquery here
<% } %>

执行jquery函数意味着什么?Javascript在客户端机器上,而您在服务器端。没错。是否有一种根据代码隐藏结果执行javascript函数的方法。是否使用任何更新面板?或者在这次回发之后,整个页面将被重新加载到客户端机器上?不,我可以试试这个解决方案。谢谢,刚才发生什么事了?我会把它放在我的答案里:
protected bool myResult {get;set;}
<% if (myResult)
  { %>
    //Do Jquery here
<% } %>
protected void Datagrid_DataBound(object sender, EventArgs e)
{
   //Cast your Datagrid datasource to Dataset
   //Loop through the dataset
   //Cast the button (.Controls[1] is important to identify the button child control)


   System.Web.UI.WebControls.Button btn =(System.Web.UI.WebControls.Button)row.Cells[x].Controls[1];
   btn.Attributes.Add("onclick", "jquery_function_name()");
}