deleting datagrid row

T

Tim Seaburn

after filling a datagrid from code, I now need to delete rows in the grid
based on some conditions. Can this be done in the ItemDataBound or
ItemCreated events? if not is there any other way to explicitly delete a
row before it displays?
thanks,
G
 
A

ashelley

after filling a datagrid from code, I now need to delete rows in the grid
based on some conditions. Can this be done in the ItemDataBound or
ItemCreated events? if not is there any other way to explicitly delete a
row before it displays?
thanks,
G

Yes. If you are using a DataView object to bind to a datagrid then
research its rowfilter propery.

-Adam
 
Joined
Jun 28, 2006
Messages
2
Reaction score
0
Use e.Item.Visible = false;

To hide the row from being displayed you can use the DataGridItemEventArgs.Item.Visible property:
e.Item.Visible = false;

So, here's what the event handler might look like:

protected void grid_ItemDataBound(object sender, DataGridItemEventArgs e) {
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
DataRowView dv = (DataRowView)e.Item.DataItem;
if (dv["foo"].ToString() == "bar") e.Item.Visible = false;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top