Enable and disable link button on gridview

前端 未结 2 1367
悲哀的现实
悲哀的现实 2021-01-19 19:12

I wants to enable or disable linkbutton on some rows of gridview based on condition.. Can i enable linkbutton on one row and disable it on another row of same grid view ??my

2条回答
  •  日久生厌
    2021-01-19 19:41

        --------aspx page code---------
    
         
                            
         
                                
                                   
                                
                                
                                    
                            
                            
                                
                                   
                                
                                
                                    
                            
                        
    
    
    
    
        ------------aspx.cs page code------------------
    
     protected void gvLibrary_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string nbps = e.Row.Cells[8].Text;
                if(nbps== " ")
                {
                    nbps = "";
                }
                else
                {
                    nbps = e.Row.Cells[8].Text;
                }
                if (nbps == "")
                {
                    LinkButton btn = (LinkButton)e.Row.FindControl("lnkissue");
                    LinkButton btn1 = (LinkButton)e.Row.FindControl("lnkReceive");
                    btn.Enabled = true;
                    btn1.Enabled = false;
                    btn1.ForeColor = System.Drawing.Color.Red;
    
                }
                else
                {
                    LinkButton btn = (LinkButton)e.Row.FindControl("lnkissue");
                    LinkButton btn1 = (LinkButton)e.Row.FindControl("lnkReceive");
                    btn.Enabled = false;
                    btn.ForeColor = System.Drawing.Color.Red;
                    btn1.Enabled = true;
                }
    
            }
        }
    

提交回复
热议问题