• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1474
  • Last Modified:

DataGrid OnItemDataBound Event

I have a data grid control that lists a bunch of aggregate data against a list of entities.  In a case where the entity has 0 in each column i need to remove that row from the grid so it isn't shown.

I understand the datagrid control is only visible from the client side but any documentation I have about the onDataBind event details writing this code to the server side.  So this has confused me considerably.

How can I achieve this?

To test an idea I tried this in the HTML (and wrote a little function called removezerorows) but I get a compile error.
<asp:datagrid id="grdBudget" OnItemDataBound="RemoveZeroRows();"

function RemoveZeroRows()
{
      alert('Removing Zero Row');
}
0
billy21
Asked:
billy21
  • 2
  • 2
1 Solution
 
billy21Author Commented:
I also need to know how to remove the row and how I can access the item that is being databound.
0
 
tusharashahCommented:
You can Access those rows like folling in your ItemDataBound event..

----------------------------------------------------------------------------------------------------------------
//In Following code I'm hiding rows for wich TotalSales is less then 100....

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
      switch( e.Item.ItemType )
      {
            case ListItemType.Item:
            case ListItemType.AlternatingItem:

            double TotalSales = Convert.ToDouble( e.Item.Cells[7].Text );  //TotalSales
                       if ( TotalSales < 100 ) e.Item.Visible = false;

            break;
      }
}
----------------------------------------------------------------------------------------------------------------

-tushar
0
 
billy21Author Commented:
Sorry but need it in VB and need to actually remove the rows.
0
 
tusharashahCommented:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
 Select e.Item.ItemType
 Case ListItemType.Item, ListItemType.AlternatingItem
   Dim TotalSales As Double = Convert.ToDouble(e.Item.Cells(7).Text)
   If TotalSales < 100 Then
     e.Item.Visible = False
   End If
   ' break
 End Select
End Sub
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now