Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

Want to disable a Button column based on other column text .
Posted
Comments
vijay__p 9-May-13 1:01am    
Can you plase elaborate our question more in detail?
Rockstar_ 9-May-13 1:06am    
I have a datagridview, that contains some data, the last column is a button column, now based on the 1 column text , suppose the text is "Clear", then disable the button in last column.

In Datagridview's cell value changed event,
C#
if(dataGridView1.Rows[e.RowIndex].Cells["yourcolumn"].Value == "Clear")
{
     dataGridView1.Rows[e.RowIndex].Cells["yourBtnColumn"].ReadOnly = True;
     dataGridView1.Rows[e.RowIndex].Cells["yourBtnColumn"].DefaultCellStyle.BackColor = color.gray;
}
else
{
     dataGridView1.Rows[e.RowIndex].Cells["yourBtnColumn"].ReadOnly = False;
     dataGridView1.Rows[e.RowIndex].Cells["yourBtnColumn"].DefaultCellStyle.BackColor =  dataGridView1.Rows[e.RowIndex].Cells["yourBtnColumn"].OwningColumn.DefaultCellStyle.BackColor;
}

Happy Coding!
:)
 
Share this answer
 
This works for Web Application...

Use RowDatabound Event
Here you go
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          Label lbl1 = (Label)e.Row.FindControl("myLabel");
          Button btn1 = ((Button)e.Row.FindControl("myButton"));
          if(lbl.Value == "")
               btn1.Enabled = false;
          else
               btn1.Enabled= true;
      }
  }


Here "myLabel" and "myButton" are the ID of the controls in gridview

For more info...have a look at this
rowdatabound-event-of-gridview-of.html[^]



If you are working on Windows app, then use CellFormatting event of datragridview...
Here is a sample...
windows-forms-datagridview-cellformatting[^]
 
Share this answer
 
v2
Comments
Rockstar_ 9-May-13 1:33am    
i'm working on windows dear not web..
Naz_Firdouse 9-May-13 2:07am    
Please see my updated answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900