1 protected void rptGrants_ItemDataBound(object sender, RepeaterItemEventArgs e)
2 {
3 DataRowView drv = (DataRowView)e.Item.DataItem;
4 if (drv["fieldName"].ToString() == "")
5 {
6 HtmlTableRow tRow = (HtmlTableRow)e.Item.FindControl("tableRowID");
7 tRow.Visible = false;
8 }
9 }
Again, I was using a repeater, and called a class method to bind the data to a DataTable. In the first line, we're accessing the data that is currently being bound to the repeater control - note that this event (ItemDataBound) is fired as the repeater iterates and binds to each row of your data. The item the repeater binds to is a DataRowView - your row of data has been turned into this DataRowView to give it more properties which enable the Repeater to do things like sort and filter, etc.
So, in line 2, I examine the specific column I'm interested in to see if there's anything there to display. Since this column is of varchar type, I check if it's empty.
Next I need to use the FindControl method to call the table row I want to hide, if the field I'm looking at is indeed empty.
That's all there was to it! Note that if my repeater had anything other than ItemTemplates or AlternateItemTemplates in it, I would have tested for the template type before the rest of my code.
References:
http://idunno.org/archive/2004/10/30/145.aspx
http://www.velocityreviews.com/forums/showpost.php?p=526696&postcount=4
More on DataRowView:
http://books.google.com/books?id=tKytuTyw3boC&pg=PA461&dq=datarowview&ei=d9pVStW2OIWQNvL5zPsJ