Really urgent : Programmatically deleting Datagrid rows

J

John

Hi all,

I searched everywhere today but to no avail - I need to programmatically
remove rows (DataGridItems) from a datagrid. Unfortunately,I can't have a
delete button/control of any kind but must do it in the ItemDataBound event.

Surely there must be a way to do this.

Any help regarding this would already be more than Google could offer.

Regards
John.
 
N

needin4mation

I'm not sure your question makes sense, sorry. You want to simply not
display items before they are rendered? Delete buttons would not make
sense in this context at all, so I am not sure why they are mentioned.
Are you asking how not to include certain rows in a datagrid given a
result set from a database?
 
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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top