2014-09-19 80 views
0

我有两个LinkButton's在我的GridView中被称为批准和拒绝,我希望我的批准LinkButton在点击它时为Disabled。我尝试了下面的代码,但它不工作。如何在点击时禁用gridview中的链接按钮

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(); 
      } 
     } 

} 
+0

你能添加'GetManagerTimeSheets'方法的代码? – ekad 2014-09-22 02:08:45

回答

0

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

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 
    } 
} 
+0

如果你不介意你能否显示一个例子 – keerthi 2014-09-19 16:03:36

0

那么你还没有表现出你的aspx链接按钮,所以我假设你的链接按钮是这个

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

现在,你应该在网页::

上添加javascript函数这样
<script> 
function Disable(link) 
{ 
link.disabled = result; 
} 
</script> 

现在当你点击页面时,你的按钮将被禁用。

+0

它只是按照要求禁用你的链接按钮! – yogi970 2014-09-19 05:25:47

+0

这不工作... – keerthi 2014-09-19 15:26:28

0

试试这个

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

我收到错误...不工作 – keerthi 2014-09-19 16:04:31