Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

How can we hide the datarow/ cells of datarow in specific DataRow in datatable.
Posted
Updated 19-Nov-12 17:50pm
v3
Comments
Savalia Manoj M 19-Nov-12 23:18pm    
please specify your question.
What you want to? You want to remove row from datatable or hide row from grid?

Hello,

you can set the row hidden in the grid view control in its databound event as follows:

C#
protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
         if(conditionToHideRow== true)
        {
           e.Row.Style.Add("visibility", "hidden");
           e.Row.Style.Add("display", "none");
        }
     }
}
 
Share this answer
 
v2
The Gridview has an event named “RowDataBound”. You can add following code in that event
e.Row.Cells[0].Visible=false;
 
Share this answer
 
v2
C#
dt.Rows.Remove(row)


It will remove the row from your datatable dt
 
Share this answer
 
Comments
Srinubabu Ravilla 19-Nov-12 23:48pm    
We can remove the rows in data table by using datatable.remove() method but my requirement is to hide the row of datatable.
NAPorwal(8015059) 20-Nov-12 0:44am    
in so far as I understand u dont want to delete the data but want to hide it.
The final task of datatable is ,data to be populated in some data control if u dont want some of data rows to populate then u can use filter that will automatically return the filtered data ,means no need to delete neither to hide any row and the datatable will contain all actual value.

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