Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.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
C# 如何在单击gridview时禁用链接按钮_C#_Asp.net_Gridview - Fatal编程技术网

C# 如何在单击gridview时禁用链接按钮

C# 如何在单击gridview时禁用链接按钮,c#,asp.net,gridview,C#,Asp.net,Gridview,我在我的网格视图中有两个链接按钮名为Approve和Reject,我希望我的Approve链接按钮在单击时被禁用。我尝试了以下代码,但不起作用 protected void gvManagerTimeSheet_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ApproveRow") { GridViewRow row = (G

我在我的
网格视图中有两个
链接按钮
名为Approve和Reject,我希望我的Approve
链接按钮
在单击时被禁用。我尝试了以下代码,但不起作用

protected void gvManagerTimeSheet_RowCommand(object sender, GridViewCommandEventArgs e)   
{
        if (e.CommandName == "ApproveRow")
        {
            GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
            LinkButton lnkbtn = (LinkButton)row.FindControl("lbApprove");
            lnkbtn.Enabled = false;

            int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
            int TimeSheetId = Convert.ToInt32(e.CommandArgument);

            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("spApproveTimeSheet ", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@TimeSheetId", TimeSheetId);

                con.Open();
                cmd.ExecuteNonQuery();

                GetManagerTimeSheets();
            }
         }

}

您需要使用禁用的控件重新绑定网格,但还需要检查itembound event和disable中的状态。为此,您可以使用会话或隐藏字段

protected void rg_OnItemCommand(object source, GridCommandEventArgs e)
{
   // your logic 
   hdFlag.value = "val" // id of the data item to hide if more than one use array
  // rebind logic for gird
}

protected void rg_ItemDataBound(object sender, GridItemEventArgs e)
{
  if(hdFlag.value == "id")
  {
    // Find the control and hide 
  }
}

你还没有显示你的aspx链接按钮,所以我假设你的链接按钮是这个

<asp:LinkButton id="linkBtn" runat="server" text="Approve"  OnClientClick="Disable(this);"/>

现在,您应该在页面上添加如下javascript函数:

<script>
function Disable(link)
{
link.disabled = result;
}
</script>

功能禁用(链接)
{
link.disabled=结果;
}
现在,当您单击页面时,您的按钮将被禁用

试试这个

 LinkButton lbApprove = (LinkButton)e.Row.Cells[0].Controls[0];

它只需根据需要禁用您的链接按钮!您可以添加
getManagerItemSheets
方法的代码吗?