Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid filtering

Status
Not open for further replies.

Garreth21

Programmer
May 19, 2005
29
Hi everyone,

I have a datagrid that I need to filter depending on a value in a column. If the column has certain data, then I want to show that row, if it doesn't then I don't want to show it. Can I do the checking for this in the ItemDataBound event or is that too late?

If anyone can give me some advice on how to go about this it would be much appreciated.

thanks
 
1. "Best" to filter in your SQL Statement first

2. onItemDataBound
Code:
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.SelectedItem)
{
    if (DataBinder.Eval(e.Item.DataItem, "myColumn").ToString() == "SomeValue")
    {
        e.Item.Visible = false;
    }
    else
    {
        e.Item.Visible = true;
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top